Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Mini tail implementation for busybox |
| 4 | * |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 5 | * Copyright (C) 2001 by Matt Kraai <kraai@alumni.carnegiemellon.edu> |
| 6 | * |
Rob Landley | f8fd4db | 2006-01-30 01:30:39 +0000 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Erik Andersen | 3fe39dc | 2000-01-25 18:13:53 +0000 | [diff] [blame] | 8 | */ |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 9 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 10 | /* BB_AUDIT SUSv3 compliant (need fancy for -c) */ |
| 11 | /* BB_AUDIT GNU compatible -c, -q, and -v options in 'fancy' configuration. */ |
| 12 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/tail.html */ |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 13 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 14 | /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) |
| 15 | * |
| 16 | * Pretty much rewritten to fix numerous bugs and reduce realloc() calls. |
| 17 | * Bugs fixed (although I may have forgotten one or two... it was pretty bad) |
| 18 | * 1) mixing printf/write without fflush()ing stdout |
| 19 | * 2) no check that any open files are present |
| 20 | * 3) optstring had -q taking an arg |
| 21 | * 4) no error checking on write in some cases, and a warning even then |
| 22 | * 5) q and s interaction bug |
| 23 | * 6) no check for lseek error |
| 24 | * 7) lseek attempted when count==0 even if arg was +0 (from top) |
| 25 | */ |
| 26 | |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 27 | #include "busybox.h" |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 28 | |
Matt Kraai | a164c64 | 2001-02-05 17:50:03 +0000 | [diff] [blame] | 29 | static const struct suffix_mult tail_suffixes[] = { |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 30 | { "b", 512 }, |
| 31 | { "k", 1024 }, |
| 32 | { "m", 1048576 }, |
| 33 | { NULL, 0 } |
| 34 | }; |
| 35 | |
Rob Landley | f8fd4db | 2006-01-30 01:30:39 +0000 | [diff] [blame] | 36 | static int status; |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 37 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 38 | static void tail_xbb_full_write(const char *buf, size_t len) |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 39 | { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 40 | /* If we get a write error, there is really no sense in continuing. */ |
Rob Landley | 5343747 | 2006-07-16 08:14:35 +0000 | [diff] [blame] | 41 | if (full_write(STDOUT_FILENO, buf, len) < 0) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 42 | bb_perror_nomsg_and_die(); |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 45 | static void tail_xprint_header(const char *fmt, const char *filename) |
| 46 | { |
| 47 | #if defined __GLIBC__ |
| 48 | if (dprintf(STDOUT_FILENO, fmt, filename) < 0) { |
| 49 | bb_perror_nomsg_and_die(); |
| 50 | } |
| 51 | #else |
| 52 | int hdr_len = strlen(fmt) + strlen(filename); |
| 53 | char *hdr = xzalloc(hdr_len); |
| 54 | sprintf(hdr, filename, filename); |
| 55 | tail_xbb_full_write(hdr, hdr_len); |
| 56 | #endif |
| 57 | } |
| 58 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 59 | static ssize_t tail_read(int fd, char *buf, size_t count) |
| 60 | { |
| 61 | ssize_t r; |
Paul Fox | 4905434 | 2005-07-20 19:46:32 +0000 | [diff] [blame] | 62 | off_t current,end; |
| 63 | struct stat sbuf; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 64 | |
Mike Frysinger | dbc049f | 2005-07-26 22:57:51 +0000 | [diff] [blame] | 65 | end = current = lseek(fd, 0, SEEK_CUR); |
| 66 | if (!fstat(fd, &sbuf)) |
| 67 | end = sbuf.st_size; |
Rob Landley | 58a651b | 2005-08-13 00:35:00 +0000 | [diff] [blame] | 68 | lseek(fd, end < current ? 0 : current, SEEK_SET); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 69 | if ((r = safe_read(fd, buf, count)) < 0) { |
Bernhard Reutner-Fischer | 1b9d7c9 | 2006-06-03 22:45:37 +0000 | [diff] [blame] | 70 | bb_perror_msg(bb_msg_read_error); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 71 | status = EXIT_FAILURE; |
| 72 | } |
| 73 | |
| 74 | return r; |
| 75 | } |
| 76 | |
| 77 | static const char tail_opts[] = |
Glenn L McGrath | 4ef5a84 | 2003-10-31 00:35:59 +0000 | [diff] [blame] | 78 | "fn:c:" |
Bernhard Reutner-Fischer | 5816ccb | 2005-12-13 10:48:45 +0000 | [diff] [blame] | 79 | #if ENABLE_FEATURE_FANCY_TAIL |
Glenn L McGrath | 4ef5a84 | 2003-10-31 00:35:59 +0000 | [diff] [blame] | 80 | "qs:v" |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 81 | #endif |
| 82 | ; |
| 83 | |
| 84 | static const char header_fmt[] = "\n==> %s <==\n"; |
| 85 | |
Eric Andersen | 98bbd68 | 2000-07-31 17:05:58 +0000 | [diff] [blame] | 86 | int tail_main(int argc, char **argv) |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 87 | { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 88 | long count = 10; |
Denis Vlasenko | 459903b | 2006-11-27 14:44:18 +0000 | [diff] [blame] | 89 | unsigned sleep_period = 1; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 90 | int from_top = 0; |
| 91 | int follow = 0; |
| 92 | int header_threshhold = 1; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 93 | int count_bytes = 0; |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 94 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 95 | char *tailbuf; |
| 96 | size_t tailbufsize; |
| 97 | int taillen = 0; |
| 98 | int newline = 0; |
| 99 | |
| 100 | int *fds, nfiles, nread, nwrite, seen, i, opt; |
| 101 | char *s, *buf; |
| 102 | const char *fmt; |
| 103 | |
Rob Landley | f8fd4db | 2006-01-30 01:30:39 +0000 | [diff] [blame] | 104 | #if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_TAIL |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 105 | /* Allow legacy syntax of an initial numeric option without -n. */ |
Denis Vlasenko | 459903b | 2006-11-27 14:44:18 +0000 | [diff] [blame] | 106 | if (argc >= 2 && (argv[1][0] == '+' || argv[1][0] == '-') |
| 107 | && isdigit(argv[1][1]) |
| 108 | ) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 109 | optind = 2; |
| 110 | optarg = argv[1]; |
| 111 | goto GET_COUNT; |
Robert Griebl | 13c26fc | 2002-05-17 22:18:04 +0000 | [diff] [blame] | 112 | } |
Glenn L McGrath | 0bd0257 | 2005-12-11 03:09:05 +0000 | [diff] [blame] | 113 | #endif |
Robert Griebl | 13c26fc | 2002-05-17 22:18:04 +0000 | [diff] [blame] | 114 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 115 | while ((opt = getopt(argc, argv, tail_opts)) > 0) { |
Eric Andersen | d5fa3e3 | 2000-08-02 16:42:58 +0000 | [diff] [blame] | 116 | switch (opt) { |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 117 | case 'f': |
| 118 | follow = 1; |
| 119 | break; |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 120 | case 'c': |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 121 | count_bytes = 1; |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 122 | /* FALLS THROUGH */ |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 123 | case 'n': |
Rob Landley | f8fd4db | 2006-01-30 01:30:39 +0000 | [diff] [blame] | 124 | #if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_TAIL |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 125 | GET_COUNT: |
Bernhard Reutner-Fischer | 5816ccb | 2005-12-13 10:48:45 +0000 | [diff] [blame] | 126 | #endif |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 127 | count = xatol_sfx(optarg, tail_suffixes); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 128 | /* Note: Leading whitespace is an error trapped above. */ |
| 129 | if (*optarg == '+') { |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 130 | from_top = 1; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 131 | } else { |
| 132 | from_top = 0; |
| 133 | } |
| 134 | if (count < 0) { |
| 135 | count = -count; |
| 136 | } |
Eric Andersen | d5fa3e3 | 2000-08-02 16:42:58 +0000 | [diff] [blame] | 137 | break; |
Bernhard Reutner-Fischer | 5816ccb | 2005-12-13 10:48:45 +0000 | [diff] [blame] | 138 | #if ENABLE_FEATURE_FANCY_TAIL |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 139 | case 'q': |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 140 | header_threshhold = INT_MAX; |
Eric Andersen | d5fa3e3 | 2000-08-02 16:42:58 +0000 | [diff] [blame] | 141 | break; |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 142 | case 's': |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 143 | sleep_period = xatou(optarg); |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 144 | break; |
| 145 | case 'v': |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 146 | header_threshhold = 0; |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 147 | break; |
| 148 | #endif |
| 149 | default: |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 150 | bb_show_usage(); |
Eric Andersen | d5fa3e3 | 2000-08-02 16:42:58 +0000 | [diff] [blame] | 151 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 152 | } |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 153 | |
| 154 | /* open all the files */ |
| 155 | fds = (int *)xmalloc(sizeof(int) * (argc - optind + 1)); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 156 | |
| 157 | argv += optind; |
| 158 | nfiles = i = 0; |
| 159 | |
| 160 | if ((argc -= optind) == 0) { |
| 161 | struct stat statbuf; |
| 162 | |
| 163 | if (!fstat(STDIN_FILENO, &statbuf) && S_ISFIFO(statbuf.st_mode)) { |
| 164 | follow = 0; |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 165 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 166 | /* --argv; */ |
| 167 | *argv = (char *) bb_msg_standard_input; |
| 168 | goto DO_STDIN; |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 169 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 170 | |
| 171 | do { |
Denis Vlasenko | 9f73944 | 2006-12-16 23:49:13 +0000 | [diff] [blame] | 172 | if (LONE_DASH(argv[i])) { |
| 173 | DO_STDIN: |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 174 | fds[nfiles] = STDIN_FILENO; |
| 175 | } else if ((fds[nfiles] = open(argv[i], O_RDONLY)) < 0) { |
| 176 | bb_perror_msg("%s", argv[i]); |
| 177 | status = EXIT_FAILURE; |
| 178 | continue; |
| 179 | } |
| 180 | argv[nfiles] = argv[i]; |
| 181 | ++nfiles; |
| 182 | } while (++i < argc); |
| 183 | |
| 184 | if (!nfiles) { |
| 185 | bb_error_msg_and_die("no files"); |
| 186 | } |
| 187 | |
| 188 | tailbufsize = BUFSIZ; |
Glenn L McGrath | 4ef5a84 | 2003-10-31 00:35:59 +0000 | [diff] [blame] | 189 | |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 190 | /* tail the files */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 191 | if (from_top < count_bytes) { /* Each is 0 or 1, so true iff 0 < 1. */ |
| 192 | /* Hence, !from_top && count_bytes */ |
| 193 | if (tailbufsize < count) { |
| 194 | tailbufsize = count + BUFSIZ; |
| 195 | } |
| 196 | } |
Glenn L McGrath | 4ef5a84 | 2003-10-31 00:35:59 +0000 | [diff] [blame] | 197 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 198 | buf = tailbuf = xmalloc(tailbufsize); |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 199 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 200 | fmt = header_fmt + 1; /* Skip header leading newline on first output. */ |
| 201 | i = 0; |
| 202 | do { |
| 203 | /* Be careful. It would be possible to optimize the count-bytes |
| 204 | * case if the file is seekable. If you do though, remember that |
| 205 | * starting file position may not be the beginning of the file. |
| 206 | * Beware of backing up too far. See example in wc.c. |
| 207 | */ |
| 208 | if ((!(count|from_top)) && (lseek(fds[i], 0, SEEK_END) >= 0)) { |
Eric Andersen | ce98c19 | 2001-06-26 15:07:08 +0000 | [diff] [blame] | 209 | continue; |
| 210 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 211 | |
| 212 | if (nfiles > header_threshhold) { |
| 213 | tail_xprint_header(fmt, argv[i]); |
| 214 | fmt = header_fmt; |
| 215 | } |
| 216 | |
| 217 | buf = tailbuf; |
| 218 | taillen = 0; |
| 219 | seen = 1; |
Glenn L McGrath | f86391e | 2004-09-30 00:24:21 +0000 | [diff] [blame] | 220 | newline = 0; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 221 | |
| 222 | while ((nread = tail_read(fds[i], buf, tailbufsize-taillen)) > 0) { |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 223 | if (from_top) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 224 | nwrite = nread; |
| 225 | if (seen < count) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 226 | if (count_bytes) { |
| 227 | nwrite -= (count - seen); |
| 228 | seen = count; |
Glenn L McGrath | 4ef5a84 | 2003-10-31 00:35:59 +0000 | [diff] [blame] | 229 | } else { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 230 | s = buf; |
| 231 | do { |
| 232 | --nwrite; |
| 233 | if ((*s++ == '\n') && (++seen == count)) { |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 234 | break; |
| 235 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 236 | } while (nwrite); |
| 237 | } |
| 238 | } |
| 239 | tail_xbb_full_write(buf + nread - nwrite, nwrite); |
| 240 | } else if (count) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 241 | if (count_bytes) { |
| 242 | taillen += nread; |
| 243 | if (taillen > count) { |
| 244 | memmove(tailbuf, tailbuf + taillen - count, count); |
| 245 | taillen = count; |
| 246 | } |
Glenn L McGrath | 4ef5a84 | 2003-10-31 00:35:59 +0000 | [diff] [blame] | 247 | } else { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 248 | int k = nread; |
| 249 | int nbuf = 0; |
| 250 | |
| 251 | while (k) { |
| 252 | --k; |
| 253 | if (buf[k] == '\n') { |
| 254 | ++nbuf; |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 255 | } |
| 256 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 257 | |
| 258 | if (newline + nbuf < count) { |
| 259 | newline += nbuf; |
| 260 | taillen += nread; |
| 261 | |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 262 | } else { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 263 | int extra = 0; |
| 264 | if (buf[nread-1] != '\n') { |
| 265 | extra = 1; |
| 266 | } |
| 267 | |
| 268 | k = newline + nbuf + extra - count; |
| 269 | s = tailbuf; |
| 270 | while (k) { |
| 271 | if (*s == '\n') { |
| 272 | --k; |
| 273 | } |
| 274 | ++s; |
| 275 | } |
| 276 | |
| 277 | taillen += nread - (s - tailbuf); |
| 278 | memmove(tailbuf, s, taillen); |
| 279 | newline = count - extra; |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 280 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 281 | if (tailbufsize < taillen + BUFSIZ) { |
| 282 | tailbufsize = taillen + BUFSIZ; |
| 283 | tailbuf = xrealloc(tailbuf, tailbufsize); |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 284 | } |
Eric Andersen | d5fa3e3 | 2000-08-02 16:42:58 +0000 | [diff] [blame] | 285 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 286 | buf = tailbuf + taillen; |
Eric Andersen | d5fa3e3 | 2000-08-02 16:42:58 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
Erik Andersen | 3fe39dc | 2000-01-25 18:13:53 +0000 | [diff] [blame] | 289 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 290 | if (!from_top) { |
| 291 | tail_xbb_full_write(tailbuf, taillen); |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | taillen = 0; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 295 | } while (++i < nfiles); |
| 296 | |
| 297 | buf = xrealloc(tailbuf, BUFSIZ); |
| 298 | |
| 299 | fmt = NULL; |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 300 | |
| 301 | while (follow) { |
| 302 | sleep(sleep_period); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 303 | i = 0; |
| 304 | do { |
| 305 | if (nfiles > header_threshhold) { |
| 306 | fmt = header_fmt; |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 307 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 308 | while ((nread = tail_read(fds[i], buf, sizeof(buf))) > 0) { |
| 309 | if (fmt) { |
| 310 | tail_xprint_header(fmt, argv[i]); |
| 311 | fmt = NULL; |
| 312 | } |
| 313 | tail_xbb_full_write(buf, nread); |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 314 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 315 | } while (++i < nfiles); |
Matt Kraai | 55bccf3 | 2001-01-05 02:57:53 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | return status; |
| 319 | } |