tail -c 1 /dev/mtd3 hangs (v1.1.3)
Steven Scholz
steven.scholz at imc-berlin.de
Thu Jun 22 00:45:37 PDT 2006
Bernhard,
> How about using lseek() only for real files, i.e. (st_size > 0) and (st_rdev
> == 0) ?
>
> What do you think of
>
> static ssize_t tail_read(int fd, char *buf, size_t count)
> ...
Just in case you like it, attached a patch.
--
Steven
-------------- next part --------------
--- /home/stscholz/Temp/BUSYBOX/busybox-1.1.3/coreutils/tail.c 2006-03-22 22:16:21.000000000 +0100
+++ busybox-1.1.3/coreutils/tail.c 2006-06-22 09:42:52.000000000 +0200
@@ -65,10 +65,18 @@ static ssize_t tail_read(int fd, char *b
off_t current,end;
struct stat sbuf;
- end = current = lseek(fd, 0, SEEK_CUR);
- if (!fstat(fd, &sbuf))
+ if (fstat(fd, &sbuf) < 0) {
+ bb_perror_msg("fstat");
+ status = EXIT_FAILURE;
+ return 0;
+ }
+
+ if ( (sbuf.st_size > 0) && (sbuf.st_rdev == 0) ) {
end = sbuf.st_size;
- lseek(fd, end < current ? 0 : current, SEEK_SET);
+ current = lseek(fd, 0, SEEK_CUR);
+ lseek(fd, end < current ? 0 : current, SEEK_SET);
+ }
+
if ((r = safe_read(fd, buf, count)) < 0) {
bb_perror_msg("read");
status = EXIT_FAILURE;
More information about the busybox
mailing list