Rev | Line | |
---|
[821] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 | /*
|
---|
| 3 | * sleep implementation for busybox
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
|
---|
| 6 | *
|
---|
[1765] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
---|
[821] | 8 | */
|
---|
| 9 |
|
---|
| 10 | /* BB_AUDIT SUSv3 compliant */
|
---|
| 11 | /* BB_AUDIT GNU issues -- fancy version matches except args must be ints. */
|
---|
| 12 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/sleep.html */
|
---|
| 13 |
|
---|
| 14 | /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
|
---|
| 15 | *
|
---|
| 16 | * Rewritten to do proper arg and error checking.
|
---|
| 17 | * Also, added a 'fancy' configuration to accept multiple args with
|
---|
| 18 | * time suffixes for seconds, minutes, hours, and days.
|
---|
| 19 | */
|
---|
| 20 |
|
---|
[1765] | 21 | #include "libbb.h"
|
---|
[821] | 22 |
|
---|
[1765] | 23 | /* This is a NOFORK applet. Be very careful! */
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 | #if ENABLE_FEATURE_FANCY_SLEEP
|
---|
| 27 | static const struct suffix_mult sfx[] = {
|
---|
[821] | 28 | { "s", 1 },
|
---|
| 29 | { "m", 60 },
|
---|
| 30 | { "h", 60*60 },
|
---|
| 31 | { "d", 24*60*60 },
|
---|
[1765] | 32 | { }
|
---|
[821] | 33 | };
|
---|
| 34 | #endif
|
---|
| 35 |
|
---|
[1765] | 36 | int sleep_main(int argc, char **argv);
|
---|
[821] | 37 | int sleep_main(int argc, char **argv)
|
---|
| 38 | {
|
---|
[1765] | 39 | unsigned duration;
|
---|
[821] | 40 |
|
---|
[1765] | 41 | #if ENABLE_FEATURE_FANCY_SLEEP
|
---|
[821] | 42 |
|
---|
| 43 | if (argc < 2) {
|
---|
| 44 | bb_show_usage();
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | ++argv;
|
---|
| 48 | duration = 0;
|
---|
| 49 | do {
|
---|
[1765] | 50 | duration += xatoul_range_sfx(*argv, 0, UINT_MAX-duration, sfx);
|
---|
[821] | 51 | } while (*++argv);
|
---|
| 52 |
|
---|
[1765] | 53 | #else /* FEATURE_FANCY_SLEEP */
|
---|
[821] | 54 |
|
---|
| 55 | if (argc != 2) {
|
---|
| 56 | bb_show_usage();
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[1765] | 59 | duration = xatou(argv[1]);
|
---|
[821] | 60 |
|
---|
[1765] | 61 | #endif /* FEATURE_FANCY_SLEEP */
|
---|
[821] | 62 |
|
---|
| 63 | if (sleep(duration)) {
|
---|
| 64 | bb_perror_nomsg_and_die();
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | return EXIT_SUCCESS;
|
---|
| 68 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.