tail compat: fix header printing for tail -f
authorBartosz Golaszewski <bartekgola@gmail.com>
Mon, 14 Oct 2013 18:11:55 +0000 (20:11 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 16 Oct 2013 13:02:50 +0000 (15:02 +0200)
Makes tail -f for multiple files display the header only if another (ie. not
currently displayed) file changed.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
TODO
coreutils/tail.c

diff --git a/TODO b/TODO
index d2a085edea7010fca934fdab9c19a8bd7759b897..dcf48c2c2cb2cb793f41cf2cd5817299c0ba1dfd 100644 (file)
--- a/TODO
+++ b/TODO
@@ -127,11 +127,6 @@ patch
 
   And while we're at it, a new patch filename quoting format is apparently
   coming soon:  http://marc.theaimsgroup.com/?l=git&m=112927316408690&w=2
----
-tail
-  ./busybox tail -f foo.c~ TODO
-  should not print fmt=header_fmt for subsequent date >> TODO; i.e. only
-  fmt+ if another (not the current) file did change
 
 Architectural issues:
 
index 07c71ca4b70cb5d975410e3eb051e324d852a6d2..eab502beb660c1e3001c1554dc79480444046527 100644 (file)
@@ -105,6 +105,7 @@ int tail_main(int argc, char **argv)
 
        int *fds;
        const char *fmt;
+       int prev_fd;
 
        INIT_G();
 
@@ -309,6 +310,7 @@ int tail_main(int argc, char **argv)
                        xwrite(STDOUT_FILENO, tailbuf, taillen);
                }
        } while (++i < nfiles);
+       prev_fd = fds[i-1];
 
        tailbuf = xrealloc(tailbuf, BUFSIZ);
 
@@ -365,9 +367,10 @@ int tail_main(int argc, char **argv)
                                nread = tail_read(fd, tailbuf, BUFSIZ);
                                if (nread <= 0)
                                        break;
-                               if (fmt) {
+                               if (fmt && (fd != prev_fd)) {
                                        tail_xprint_header(fmt, filename);
                                        fmt = NULL;
+                                       prev_fd = fd;
                                }
                                xwrite(STDOUT_FILENO, tailbuf, nread);
                        }