Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/coreutils/tail.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/coreutils/tail.c
r3232 r3621 25 25 */ 26 26 27 //kbuild:lib-$(CONFIG_TAIL) += tail.o 28 27 29 //usage:#define tail_trivial_usage 28 30 //usage: "[OPTIONS] [FILE]..." … … 31 33 //usage: "With more than one FILE, precede each with a filename header.\n" 32 34 //usage: "\n -f Print data as file grows" 35 //usage: "\n -c [+]N[kbm] Print last N bytes" 36 //usage: "\n -n N[kbm] Print last N lines" 37 //usage: "\n -n +N[kbm] Start on Nth line and print the rest" 33 38 //usage: IF_FEATURE_FANCY_TAIL( 39 //usage: "\n -q Never print headers" 34 40 //usage: "\n -s SECONDS Wait SECONDS between reads with -f" 35 //usage: )36 //usage: "\n -n N[kbm] Print last N lines"37 //usage: IF_FEATURE_FANCY_TAIL(38 //usage: "\n -c N[kbm] Print last N bytes"39 //usage: "\n -q Never print headers"40 41 //usage: "\n -v Always print headers" 42 //usage: "\n -F Same as -f, but keep retrying" 41 43 //usage: "\n" 42 44 //usage: "\nN may be suffixed by k (x1024), b (x512), or m (x1024^2)." 43 //usage: "\nIf N starts with a '+', output begins with the Nth item from the start"44 //usage: "\nof each file, not from the end."45 45 //usage: ) 46 46 //usage: … … 50 50 51 51 #include "libbb.h" 52 53 static const struct suffix_mult tail_suffixes[] = { 54 { "b", 512 }, 55 { "k", 1024 }, 56 { "m", 1024*1024 }, 57 { "", 0 } 58 }; 52 #include "common_bufsiz.h" 59 53 60 54 struct globals { … … 62 56 bool exitcode; 63 57 } FIX_ALIASING; 64 #define G (*(struct globals*) &bb_common_bufsiz1)65 #define INIT_G() do { } while (0)58 #define G (*(struct globals*)bb_common_bufsiz1) 59 #define INIT_G() do { setup_common_bufsiz(); } while (0) 66 60 67 61 static void tail_xprint_header(const char *fmt, const char *filename) … … 74 68 { 75 69 ssize_t r; 76 off_t current;77 struct stat sbuf;78 79 /* /proc files report zero st_size, don't lseek them. */80 if (fstat(fd, &sbuf) == 0 && sbuf.st_size > 0) {81 current = lseek(fd, 0, SEEK_CUR);82 if (sbuf.st_size < current)83 xlseek(fd, 0, SEEK_SET);84 }85 70 86 71 r = full_read(fd, buf, count); … … 103 88 G.from_top = 1; 104 89 } 105 return xatou_sfx(p, tail_suffixes);90 return xatou_sfx(p, bkm_suffixes); 106 91 } 107 92 … … 121 106 int *fds; 122 107 const char *fmt; 108 int prev_fd; 123 109 124 110 INIT_G(); … … 325 311 } 326 312 } while (++i < nfiles); 313 prev_fd = fds[i-1]; 327 314 328 315 tailbuf = xrealloc(tailbuf, BUFSIZ); … … 368 355 fmt = header_fmt_str; 369 356 } 370 while ((nread = tail_read(fd, tailbuf, BUFSIZ)) > 0) { 371 if (fmt) { 357 for (;;) { 358 /* tail -f keeps following files even if they are truncated */ 359 struct stat sbuf; 360 /* /proc files report zero st_size, don't lseek them */ 361 if (fstat(fd, &sbuf) == 0 && sbuf.st_size > 0) { 362 off_t current = lseek(fd, 0, SEEK_CUR); 363 if (sbuf.st_size < current) 364 xlseek(fd, 0, SEEK_SET); 365 } 366 367 nread = tail_read(fd, tailbuf, BUFSIZ); 368 if (nread <= 0) 369 break; 370 if (fmt && (fd != prev_fd)) { 372 371 tail_xprint_header(fmt, filename); 373 372 fmt = NULL; 373 prev_fd = fd; 374 374 } 375 375 xwrite(STDOUT_FILENO, tailbuf, nread);
Note:
See TracChangeset
for help on using the changeset viewer.