diff options
Diffstat (limited to 'toys/posix/tail.c')
-rw-r--r-- | toys/posix/tail.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/toys/posix/tail.c b/toys/posix/tail.c index f34e10cc..514bd5b8 100644 --- a/toys/posix/tail.c +++ b/toys/posix/tail.c @@ -36,8 +36,7 @@ GLOBALS( struct { char *path; int fd; - dev_t dev; - ino_t ino; + struct dev_ino di; } *F; ) @@ -159,12 +158,12 @@ static void tail_continue() continue; } - if (fd<0 || sb.st_dev!=TT.F[i].dev || sb.st_ino!=TT.F[i].ino) { + if (fd<0 || !same_dev_ino(&sb, &TT.F[i].di)) { if (fd>=0) close(fd); if (-1 == (TT.F[i].fd = fd = open(path, O_RDONLY))) continue; error_msg("following new file: %s\n", path); - TT.F[i].dev = sb.st_dev; - TT.F[i].ino = sb.st_ino; + TT.F[i].di.dev = sb.st_dev; + TT.F[i].di.ino = sb.st_ino; } else if (sb.st_size <= (pos = lseek(fd, 0, SEEK_CUR))) { if (pos == sb.st_size) continue; error_msg("file truncated: %s\n", path); @@ -201,8 +200,8 @@ static void do_tail(int fd, char *name) if (FLAG(F)) { if (fd != -1) { if (fstat(fd, &sb)) perror_exit("%s", name); - TT.F[TT.file_no].dev = sb.st_dev; - TT.F[TT.file_no].ino = sb.st_ino; + TT.F[TT.file_no].di.dev = sb.st_dev; + TT.F[TT.file_no].di.ino = sb.st_ino; } TT.F[TT.file_no].fd = fd; TT.F[TT.file_no].path = s; @@ -290,8 +289,8 @@ void tail_main(void) if (!FLAG(n) && !FLAG(c)) { char *arg = *args; - // handle old "-42" style arguments, else default to last 10 lines - if (arg && *arg == '-' && arg[1]) { + // handle old "-42" / "+42" style arguments, else default to last 10 lines + if (arg && (*arg == '-' || *arg == '+') && arg[1]) { TT.n = atolx(*(args++)); toys.optc--; } else TT.n = -10; @@ -302,7 +301,7 @@ void tail_main(void) TT.ss = TT.s ? xparsemillitime(TT.s) : 1000; loopfiles_rw(args, - O_RDONLY|WARN_ONLY|LOOPFILES_ANYWAY|(O_CLOEXEC*!(FLAG(f) || FLAG(F))), + O_RDONLY|WARN_ONLY|LOOPFILES_ANYWAY|O_CLOEXEC*!(FLAG(f) || FLAG(F)), 0, do_tail); // Wait for more data when following files |