summaryrefslogtreecommitdiffhomepage
path: root/coreutils
diff options
context:
space:
mode:
authorBartosz Golaszewski <bartekgola@gmail.com>2013-10-14 20:11:55 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2013-10-16 15:02:50 +0200
commit64938011f3ba06a8f425926397172dc361bce851 (patch)
treed3e406ab6e54d9235b6f7e9e03534d3ef064260a /coreutils
parent840ef17f63c85044c15d9a38a13c6539e26dfc31 (diff)
tail compat: fix header printing for tail -f
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>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/tail.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/coreutils/tail.c b/coreutils/tail.c
index 07c71ca4b..eab502beb 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -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);
}