Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/coreutils/tail.c


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/coreutils/tail.c

    r3232 r3621  
    2525 */
    2626
     27//kbuild:lib-$(CONFIG_TAIL) += tail.o
     28
    2729//usage:#define tail_trivial_usage
    2830//usage:       "[OPTIONS] [FILE]..."
     
    3133//usage:       "With more than one FILE, precede each with a filename header.\n"
    3234//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"
    3338//usage:    IF_FEATURE_FANCY_TAIL(
     39//usage:     "\n    -q      Never print headers"
    3440//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"
    4041//usage:     "\n    -v      Always print headers"
     42//usage:     "\n    -F      Same as -f, but keep retrying"
    4143//usage:     "\n"
    4244//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."
    4545//usage:    )
    4646//usage:
     
    5050
    5151#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"
    5953
    6054struct globals {
     
    6256    bool exitcode;
    6357} 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)
    6660
    6761static void tail_xprint_header(const char *fmt, const char *filename)
     
    7468{
    7569    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     }
    8570
    8671    r = full_read(fd, buf, count);
     
    10388        G.from_top = 1;
    10489    }
    105     return xatou_sfx(p, tail_suffixes);
     90    return xatou_sfx(p, bkm_suffixes);
    10691}
    10792
     
    121106    int *fds;
    122107    const char *fmt;
     108    int prev_fd;
    123109
    124110    INIT_G();
     
    325311        }
    326312    } while (++i < nfiles);
     313    prev_fd = fds[i-1];
    327314
    328315    tailbuf = xrealloc(tailbuf, BUFSIZ);
     
    368355                fmt = header_fmt_str;
    369356            }
    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)) {
    372371                    tail_xprint_header(fmt, filename);
    373372                    fmt = NULL;
     373                    prev_fd = fd;
    374374                }
    375375                xwrite(STDOUT_FILENO, tailbuf, nread);
Note: See TracChangeset for help on using the changeset viewer.