Skip to content

Commit 6493801

Browse files
brglDenys Vlasenko
authored andcommitted
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 <[email protected]> Signed-off-by: Denys Vlasenko <[email protected]>
1 parent 840ef17 commit 6493801

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

TODO

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@ patch
127127

128128
And while we're at it, a new patch filename quoting format is apparently
129129
coming soon: http://marc.theaimsgroup.com/?l=git&m=112927316408690&w=2
130-
---
131-
tail
132-
./busybox tail -f foo.c~ TODO
133-
should not print fmt=header_fmt for subsequent date >> TODO; i.e. only
134-
fmt+ if another (not the current) file did change
135130

136131
Architectural issues:
137132

coreutils/tail.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ int tail_main(int argc, char **argv)
105105

106106
int *fds;
107107
const char *fmt;
108+
int prev_fd;
108109

109110
INIT_G();
110111

@@ -309,6 +310,7 @@ int tail_main(int argc, char **argv)
309310
xwrite(STDOUT_FILENO, tailbuf, taillen);
310311
}
311312
} while (++i < nfiles);
313+
prev_fd = fds[i-1];
312314

313315
tailbuf = xrealloc(tailbuf, BUFSIZ);
314316

@@ -365,9 +367,10 @@ int tail_main(int argc, char **argv)
365367
nread = tail_read(fd, tailbuf, BUFSIZ);
366368
if (nread <= 0)
367369
break;
368-
if (fmt) {
370+
if (fmt && (fd != prev_fd)) {
369371
tail_xprint_header(fmt, filename);
370372
fmt = NULL;
373+
prev_fd = fd;
371374
}
372375
xwrite(STDOUT_FILENO, tailbuf, nread);
373376
}

0 commit comments

Comments
 (0)