diff options
-rwxr-xr-x | tests/tail.test | 15 | ||||
-rw-r--r-- | toys/posix/tail.c | 10 |
2 files changed, 20 insertions, 5 deletions
diff --git a/tests/tail.test b/tests/tail.test index b3d744aa..c1c44c6a 100755 --- a/tests/tail.test +++ b/tests/tail.test @@ -59,3 +59,18 @@ testing "-c 12345 -n 3 bigfile" "tail -c 12345 -n 3 bigfile | md5sum" \ "347bbdcbad8a313f4dc7bd558c5bfcb8 -\n" "" "" testing "-n 3 -c 12345 bigfile" "tail -n 3 -c 12345 bigfile | md5sum" \ "1698825a750288284ec3ba7d8a59f302 -\n" "" "" +rm bigfile + +echo 111 > one +testing "-f one" \ + 'tail -f one & sleep .25 ; echo two >> one; sleep .25; echo three >> one; sleep .25; kill $! >/dev/null' \ + "111\ntwo\nthree\n" "" "" +rm one + +echo uno > one +echo dos > two +echo tres > three +testing "-f one two three" \ + 'tail -f one two three & sleep .25 ; echo more >> three ; echo also >> one; sleep .25; kill $! >/dev/null' \ + "==> one <==\nuno\n\n==> two <==\ndos\n\n==> three <==\ntres\nmore\n\n==> one <==\nalso\n" "" "" +rm one two three diff --git a/toys/posix/tail.c b/toys/posix/tail.c index bf25a149..1204f1c6 100644 --- a/toys/posix/tail.c +++ b/toys/posix/tail.c @@ -3,6 +3,8 @@ * Copyright 2012 Timothy Elliott <tle@holymonkey.com> * * See http://opengroup.org/onlinepubs/9699919799/utilities/tail.html + * + * Deviations from posix: -f waits for pipe/fifo on stdin (nonblock?). USE_TAIL(NEWTOY(tail, "?fc-n-[-cn]", TOYFLAG_USR|TOYFLAG_BIN)) @@ -136,7 +138,7 @@ static void do_tail(int fd, char *name) int linepop = 1; if (toys.optflags & FLAG_f) { - int f = (TT.file_no++)*2; + int f = TT.file_no*2; char *s = name; if (!fd) sprintf(s = toybuf, "/proc/self/fd/%d", fd); @@ -145,10 +147,8 @@ static void do_tail(int fd, char *name) perror_msg("bad -f on '%s'", name); } - if (toys.optc > 1) { - if (TT.file_no) xputc('\n'); - xprintf("==> %s <==\n", name); - } + if (TT.file_no++) xputc('\n'); + if (toys.optc > 1) xprintf("==> %s <==\n", name); // Are we measuring from the end of the file? |