Ignore:
Timestamp:
Nov 6, 2007, 11:01:53 AM (16 years ago)
Author:
Bruno Cornec
Message:
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

File:
1 edited

Legend:

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

    r821 r1770  
    2525 */
    2626
    27 #include <stdio.h>
    28 #include <stdlib.h>
    29 #include <string.h>
    30 #include <ctype.h>
    31 #include <unistd.h>
    32 #include <fcntl.h>
    33 #include <sys/stat.h>
    34 #include "busybox.h"
     27#include "libbb.h"
    3528
    3629static const struct suffix_mult tail_suffixes[] = {
    3730    { "b", 512 },
    3831    { "k", 1024 },
    39     { "m", 1048576 },
    40     { NULL, 0 }
     32    { "m", 1024*1024 },
     33    { }
    4134};
    4235
    43 static int status;
     36struct globals {
     37    bool status;
     38};
     39#define G (*(struct globals*)&bb_common_bufsiz1)
    4440
    4541static void tail_xprint_header(const char *fmt, const char *filename)
    4642{
    47     /* If we get an output error, there is really no sense in continuing. */
    48     if (dprintf(STDOUT_FILENO, fmt, filename) < 0) {
     43    if (fdprintf(STDOUT_FILENO, fmt, filename) < 0)
    4944        bb_perror_nomsg_and_die();
    50     }
    51 }
    52 
    53 /* len should probably be size_t */
    54 static void tail_xbb_full_write(const char *buf, size_t len)
    55 {
    56     /* If we get a write error, there is really no sense in continuing. */
    57     if (bb_full_write(STDOUT_FILENO, buf, len) < 0) {
    58         bb_perror_nomsg_and_die();
    59     }
    6045}
    6146
     
    6348{
    6449    ssize_t r;
    65     off_t current,end;
     50    off_t current, end;
    6651    struct stat sbuf;
    6752
     
    7055        end = sbuf.st_size;
    7156    lseek(fd, end < current ? 0 : current, SEEK_SET);
    72     if ((r = safe_read(fd, buf, count)) < 0) {
     57    r = safe_read(fd, buf, count);
     58    if (r < 0) {
    7359        bb_perror_msg(bb_msg_read_error);
    74         status = EXIT_FAILURE;
     60        G.status = EXIT_FAILURE;
    7561    }
    7662
     
    7864}
    7965
    80 static const char tail_opts[] =
    81     "fn:c:"
    82 #if ENABLE_FEATURE_FANCY_TAIL
    83     "qs:v"
    84 #endif
    85     ;
    86 
    87 static const char header_fmt[] = "\n==> %s <==\n";
    88 
     66static const char header_fmt[] ALIGN1 = "\n==> %s <==\n";
     67
     68static unsigned eat_num(const char *p)
     69{
     70    if (*p == '-') p++;
     71    else if (*p == '+') { p++; G.status = EXIT_FAILURE; }
     72    return xatou_sfx(p, tail_suffixes);
     73}
     74
     75int tail_main(int argc, char **argv);
    8976int tail_main(int argc, char **argv)
    9077{
    91     long count = 10;
    92     unsigned int sleep_period = 1;
    93     int from_top = 0;
    94     int follow = 0;
     78    unsigned count = 10;
     79    unsigned sleep_period = 1;
     80    bool from_top;
    9581    int header_threshhold = 1;
    96     int count_bytes = 0;
     82    const char *str_c, *str_n;
     83    USE_FEATURE_FANCY_TAIL(const char *str_s;)
    9784
    9885    char *tailbuf;
     
    10087    int taillen = 0;
    10188    int newline = 0;
    102 
    103     int *fds, nfiles, nread, nwrite, seen, i, opt;
     89    int nfiles, nread, nwrite, seen, i, opt;
     90
     91    int *fds;
    10492    char *s, *buf;
    10593    const char *fmt;
    10694
    107 #if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_TAIL
     95#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_TAIL
    10896    /* Allow legacy syntax of an initial numeric option without -n. */
    109     if (argc >=2 && ((argv[1][0] == '+') || ((argv[1][0] == '-')
    110             /* && (isdigit)(argv[1][1]) */
    111             && (((unsigned int)(argv[1][1] - '0')) <= 9))))
    112     {
    113         optind = 2;
    114         optarg = argv[1];
    115         goto GET_COUNT;
    116     }
     97    if (argc >= 2 && (argv[1][0] == '+' || argv[1][0] == '-')
     98     && isdigit(argv[1][1])
     99    ) {
     100        /* replacing arg[0] with "-n" can segfault, so... */
     101        argv[1] = xasprintf("-n%s", argv[1]);
     102#if 0 /* If we ever decide to make tail NOFORK */
     103        char *s = alloca(strlen(argv[1]) + 3);
     104        sprintf(s, "-n%s", argv[1]);
     105        argv[1] = s;
    117106#endif
    118 
    119     while ((opt = getopt(argc, argv, tail_opts)) > 0) {
    120         switch (opt) {
    121             case 'f':
    122                 follow = 1;
    123                 break;
    124             case 'c':
    125                 count_bytes = 1;
    126                 /* FALLS THROUGH */
    127             case 'n':
    128 #if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_TAIL
    129             GET_COUNT:
     107    }
    130108#endif
    131                 count = bb_xgetlarg10_sfx(optarg, tail_suffixes);
    132                 /* Note: Leading whitespace is an error trapped above. */
    133                 if (*optarg == '+') {
    134                     from_top = 1;
    135                 } else {
    136                     from_top = 0;
    137                 }
    138                 if (count < 0) {
    139                     count = -count;
    140                 }
    141                 break;
     109
     110    opt = getopt32(argv, "fc:n:" USE_FEATURE_FANCY_TAIL("qs:v"),
     111            &str_c, &str_n USE_FEATURE_FANCY_TAIL(,&str_s));
     112#define FOLLOW (opt & 0x1)
     113#define COUNT_BYTES (opt & 0x2)
     114    //if (opt & 0x1) // -f
     115    if (opt & 0x2) count = eat_num(str_c); // -c
     116    if (opt & 0x4) count = eat_num(str_n); // -n
    142117#if ENABLE_FEATURE_FANCY_TAIL
    143             case 'q':
    144                 header_threshhold = INT_MAX;
    145                 break;
    146             case 's':
    147                 sleep_period =bb_xgetularg10_bnd(optarg, 0, UINT_MAX);
    148                 break;
    149             case 'v':
    150                 header_threshhold = 0;
    151                 break;
     118    if (opt & 0x8) header_threshhold = INT_MAX; // -q
     119    if (opt & 0x10) sleep_period = xatou(str_s); // -s
     120    if (opt & 0x20) header_threshhold = 0; // -v
    152121#endif
    153             default:
    154                 bb_show_usage();
    155         }
    156     }
     122    argc -= optind;
     123    argv += optind;
     124    from_top = G.status;
    157125
    158126    /* open all the files */
    159     fds = (int *)xmalloc(sizeof(int) * (argc - optind + 1));
    160 
    161     argv += optind;
     127    fds = xmalloc(sizeof(int) * (argc + 1));
    162128    nfiles = i = 0;
    163 
    164     if ((argc -= optind) == 0) {
     129    G.status = EXIT_SUCCESS;
     130    if (argc == 0) {
    165131        struct stat statbuf;
    166132
    167133        if (!fstat(STDIN_FILENO, &statbuf) && S_ISFIFO(statbuf.st_mode)) {
    168             follow = 0;
    169         }
    170         /* --argv; */
     134            opt &= ~1; /* clear FOLLOW */
     135        }
    171136        *argv = (char *) bb_msg_standard_input;
    172         goto DO_STDIN;
    173     }
    174 
     137    }
    175138    do {
    176         if ((argv[i][0] == '-') && !argv[i][1]) {
    177         DO_STDIN:
    178             fds[nfiles] = STDIN_FILENO;
    179         } else if ((fds[nfiles] = open(argv[i], O_RDONLY)) < 0) {
    180             bb_perror_msg("%s", argv[i]);
    181             status = EXIT_FAILURE;
     139        FILE* fil = fopen_or_warn_stdin(argv[i]);
     140        if (!fil) {
     141            G.status = EXIT_FAILURE;
    182142            continue;
    183143        }
    184         argv[nfiles] = argv[i];
    185         ++nfiles;
     144        fds[nfiles] = fileno(fil);
     145        argv[nfiles++] = argv[i];
    186146    } while (++i < argc);
    187147
    188     if (!nfiles) {
     148    if (!nfiles)
    189149        bb_error_msg_and_die("no files");
    190     }
    191150
    192151    tailbufsize = BUFSIZ;
    193152
    194153    /* tail the files */
    195     if (from_top < count_bytes) {   /* Each is 0 or 1, so true iff 0 < 1. */
    196         /* Hence, !from_top && count_bytes */
     154    if (!from_top && COUNT_BYTES) {
    197155        if (tailbufsize < count) {
    198156            tailbufsize = count + BUFSIZ;
     
    210168         * Beware of backing up too far.  See example in wc.c.
    211169         */
    212         if ((!(count|from_top)) && (lseek(fds[i], 0, SEEK_END) >= 0)) {
     170        if (!(count | from_top) && lseek(fds[i], 0, SEEK_END) >= 0) {
    213171            continue;
    214172        }
     
    228186                nwrite = nread;
    229187                if (seen < count) {
    230                     if (count_bytes) {
     188                    if (COUNT_BYTES) {
    231189                        nwrite -= (count - seen);
    232190                        seen = count;
     
    235193                        do {
    236194                            --nwrite;
    237                             if ((*s++ == '\n') && (++seen == count)) {
     195                            if (*s++ == '\n' && ++seen == count) {
    238196                                break;
    239197                            }
     
    241199                    }
    242200                }
    243                 tail_xbb_full_write(buf + nread - nwrite, nwrite);
     201                xwrite(STDOUT_FILENO, buf + nread - nwrite, nwrite);
    244202            } else if (count) {
    245                 if (count_bytes) {
     203                if (COUNT_BYTES) {
    246204                    taillen += nread;
    247205                    if (taillen > count) {
     
    263221                        newline += nbuf;
    264222                        taillen += nread;
    265 
    266223                    } else {
    267224                        int extra = 0;
    268                         if (buf[nread-1] != '\n') {
     225
     226                        if (buf[nread-1] != '\n')
    269227                            extra = 1;
    270                         }
    271 
    272228                        k = newline + nbuf + extra - count;
    273229                        s = tailbuf;
     
    278234                            ++s;
    279235                        }
    280 
    281236                        taillen += nread - (s - tailbuf);
    282237                        memmove(tailbuf, s, taillen);
     
    293248
    294249        if (!from_top) {
    295             tail_xbb_full_write(tailbuf, taillen);
     250            xwrite(STDOUT_FILENO, tailbuf, taillen);
    296251        }
    297252
     
    303258    fmt = NULL;
    304259
    305     while (follow) {
     260    if (FOLLOW) while (1) {
    306261        sleep(sleep_period);
    307262        i = 0;
     
    315270                    fmt = NULL;
    316271                }
    317                 tail_xbb_full_write(buf, nread);
     272                xwrite(STDOUT_FILENO, buf, nread);
    318273            }
    319274        } while (++i < nfiles);
    320275    }
    321 
    322     return status;
    323 }
     276    if (ENABLE_FEATURE_CLEAN_UP) {
     277        free(fds);
     278    }
     279    return G.status;
     280}
Note: See TracChangeset for help on using the changeset viewer.