Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/coreutils/sleep.c

    r1765 r2725  
    55 * Copyright (C) 2003  Manuel Novoa III  <mjn3@codepoet.org>
    66 *
    7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 */
    99
     
    2121#include "libbb.h"
    2222
    23 /* This is a NOFORK applet. Be very careful! */
     23/* Do not make this applet NOFORK. It breaks ^C-ing of pauses in shells */
    2424
    2525
    26 #if ENABLE_FEATURE_FANCY_SLEEP
     26#if ENABLE_FEATURE_FANCY_SLEEP || ENABLE_FEATURE_FLOAT_SLEEP
    2727static const struct suffix_mult sfx[] = {
    2828    { "s", 1 },
     
    3030    { "h", 60*60 },
    3131    { "d", 24*60*60 },
    32     { }
     32    { "", 0 }
    3333};
    3434#endif
    3535
    36 int sleep_main(int argc, char **argv);
    37 int sleep_main(int argc, char **argv)
     36int sleep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     37int sleep_main(int argc UNUSED_PARAM, char **argv)
    3838{
     39#if ENABLE_FEATURE_FLOAT_SLEEP
     40    double duration;
     41    struct timespec ts;
     42#else
    3943    unsigned duration;
    40 
    41 #if ENABLE_FEATURE_FANCY_SLEEP
    42 
    43     if (argc < 2) {
    44         bb_show_usage();
    45     }
     44#endif
    4645
    4746    ++argv;
     47    if (!*argv)
     48        bb_show_usage();
     49
     50#if ENABLE_FEATURE_FLOAT_SLEEP
     51
     52# if ENABLE_LOCALE_SUPPORT
     53    /* undo busybox.c setlocale */
     54    setlocale(LC_NUMERIC, "C");
     55# endif
    4856    duration = 0;
    4957    do {
    50         duration += xatoul_range_sfx(*argv, 0, UINT_MAX-duration, sfx);
     58        char *arg = *argv;
     59        if (strchr(arg, '.')) {
     60            double d;
     61            char *pp;
     62            int len = strspn(arg, "0123456789.");
     63            char sv = arg[len];
     64            arg[len] = '\0';
     65            errno = 0;
     66            d = strtod(arg, &pp);
     67            if (errno || *pp)
     68                bb_show_usage();
     69            arg += len;
     70            *arg-- = sv;
     71            sv = *arg;
     72            *arg = '1';
     73            duration += d * xatoul_sfx(arg, sfx);
     74            *arg = sv;
     75        } else {
     76            duration += xatoul_sfx(arg, sfx);
     77        }
    5178    } while (*++argv);
    5279
    53 #else  /* FEATURE_FANCY_SLEEP */
     80    ts.tv_sec = MAXINT(typeof(ts.tv_sec));
     81    ts.tv_nsec = 0;
     82    if (duration >= 0 && duration < ts.tv_sec) {
     83        ts.tv_sec = duration;
     84        ts.tv_nsec = (duration - ts.tv_sec) * 1000000000;
     85    }
     86    do {
     87        errno = 0;
     88        nanosleep(&ts, &ts);
     89    } while (errno == EINTR);
    5490
    55     if (argc != 2) {
    56         bb_show_usage();
    57     }
     91#elif ENABLE_FEATURE_FANCY_SLEEP
    5892
    59     duration = xatou(argv[1]);
     93    duration = 0;
     94    do {
     95        duration += xatou_range_sfx(*argv, 0, UINT_MAX - duration, sfx);
     96    } while (*++argv);
     97    sleep(duration);
    6098
    61 #endif /* FEATURE_FANCY_SLEEP */
     99#else /* simple */
    62100
    63     if (sleep(duration)) {
    64         bb_perror_nomsg_and_die();
    65     }
     101    duration = xatou(*argv);
     102    sleep(duration);
     103    // Off. If it's really needed, provide example why
     104    //if (sleep(duration)) {
     105    //  bb_perror_nomsg_and_die();
     106    //}
     107
     108#endif
    66109
    67110    return EXIT_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.