diff options
author | Ron Yorston <rmy@pobox.com> | 2018-09-10 14:37:07 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-09-10 14:59:33 +0100 |
commit | d89ced75b204f0eb5611f522864beb81d1b393f5 (patch) | |
tree | 5daa31427e287fe079a0ef551097753773fdb266 /coreutils | |
parent | f72845d9332fa6311a46dbcad3180d5008182982 (diff) | |
parent | 05b18065ab9c375f6185b65a3631d4c6cc1a4be9 (diff) | |
download | busybox-w32-d89ced75b204f0eb5611f522864beb81d1b393f5.tar.gz busybox-w32-d89ced75b204f0eb5611f522864beb81d1b393f5.tar.bz2 busybox-w32-d89ced75b204f0eb5611f522864beb81d1b393f5.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/cp.c | 2 | ||||
-rw-r--r-- | coreutils/ls.c | 10 | ||||
-rw-r--r-- | coreutils/sleep.c | 78 | ||||
-rw-r--r-- | coreutils/timeout.c | 30 |
4 files changed, 31 insertions, 89 deletions
diff --git a/coreutils/cp.c b/coreutils/cp.c index ae60623d3..b26c0e954 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c | |||
@@ -114,7 +114,7 @@ int cp_main(int argc, char **argv) | |||
114 | # endif | 114 | # endif |
115 | ); | 115 | ); |
116 | # if ENABLE_FEATURE_CP_REFLINK | 116 | # if ENABLE_FEATURE_CP_REFLINK |
117 | BUILD_BUG_ON(OPT_reflink != FILEUTILS_REFLINK); | 117 | BUILD_BUG_ON((int)OPT_reflink != (int)FILEUTILS_REFLINK); |
118 | if (flags & FILEUTILS_REFLINK) { | 118 | if (flags & FILEUTILS_REFLINK) { |
119 | if (!reflink) | 119 | if (!reflink) |
120 | flags |= FILEUTILS_REFLINK_ALWAYS; | 120 | flags |= FILEUTILS_REFLINK_ALWAYS; |
diff --git a/coreutils/ls.c b/coreutils/ls.c index b0c543d28..9daa15470 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -1018,7 +1018,15 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first) | |||
1018 | subdnp = scan_one_dir((*dn)->fullname, &nfiles); | 1018 | subdnp = scan_one_dir((*dn)->fullname, &nfiles); |
1019 | #if ENABLE_DESKTOP | 1019 | #if ENABLE_DESKTOP |
1020 | if (option_mask32 & (OPT_s|OPT_l)) { | 1020 | if (option_mask32 & (OPT_s|OPT_l)) { |
1021 | printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp)); | 1021 | if (option_mask32 & OPT_h) { |
1022 | printf("total %-"HUMAN_READABLE_MAX_WIDTH_STR"s\n", | ||
1023 | /* print size, no fractions, use suffixes */ | ||
1024 | make_human_readable_str(calculate_blocks(subdnp) * 1024, | ||
1025 | 0, 0) | ||
1026 | ); | ||
1027 | } else { | ||
1028 | printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp)); | ||
1029 | } | ||
1022 | } | 1030 | } |
1023 | #endif | 1031 | #endif |
1024 | if (nfiles > 0) { | 1032 | if (nfiles > 0) { |
diff --git a/coreutils/sleep.c b/coreutils/sleep.c index 9b9581ca9..126665839 100644 --- a/coreutils/sleep.c +++ b/coreutils/sleep.c | |||
@@ -32,13 +32,6 @@ | |||
32 | //config: depends on SLEEP | 32 | //config: depends on SLEEP |
33 | //config: help | 33 | //config: help |
34 | //config: Allow sleep to pause for specified minutes, hours, and days. | 34 | //config: Allow sleep to pause for specified minutes, hours, and days. |
35 | //config: | ||
36 | //config:config FEATURE_FLOAT_SLEEP | ||
37 | //config: bool "Enable fractional arguments" | ||
38 | //config: default y | ||
39 | //config: depends on FEATURE_FANCY_SLEEP | ||
40 | //config: help | ||
41 | //config: Allow for fractional numeric parameters. | ||
42 | 35 | ||
43 | /* Do not make this applet NOFORK. It breaks ^C-ing of pauses in shells */ | 36 | /* Do not make this applet NOFORK. It breaks ^C-ing of pauses in shells */ |
44 | //applet:IF_SLEEP(APPLET(sleep, BB_DIR_BIN, BB_SUID_DROP)) | 37 | //applet:IF_SLEEP(APPLET(sleep, BB_DIR_BIN, BB_SUID_DROP)) |
@@ -66,89 +59,28 @@ | |||
66 | 59 | ||
67 | #include "libbb.h" | 60 | #include "libbb.h" |
68 | 61 | ||
69 | #if ENABLE_FEATURE_FANCY_SLEEP || ENABLE_FEATURE_FLOAT_SLEEP | ||
70 | static const struct suffix_mult sfx[] = { | ||
71 | { "s", 1 }, | ||
72 | { "m", 60 }, | ||
73 | { "h", 60*60 }, | ||
74 | { "d", 24*60*60 }, | ||
75 | { "", 0 } | ||
76 | }; | ||
77 | #endif | ||
78 | |||
79 | int sleep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 62 | int sleep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
80 | int sleep_main(int argc UNUSED_PARAM, char **argv) | 63 | int sleep_main(int argc UNUSED_PARAM, char **argv) |
81 | { | 64 | { |
82 | #if ENABLE_FEATURE_FLOAT_SLEEP | 65 | duration_t duration; |
83 | double duration; | ||
84 | struct timespec ts; | ||
85 | #else | ||
86 | unsigned duration; | ||
87 | #endif | ||
88 | 66 | ||
89 | ++argv; | 67 | ++argv; |
90 | if (!*argv) | 68 | if (!*argv) |
91 | bb_show_usage(); | 69 | bb_show_usage(); |
92 | 70 | ||
93 | #if ENABLE_FEATURE_FLOAT_SLEEP | 71 | #if ENABLE_FEATURE_FANCY_SLEEP |
94 | 72 | # if ENABLE_FLOAT_DURATION | |
95 | # if ENABLE_LOCALE_SUPPORT | ||
96 | /* undo busybox.c setlocale */ | 73 | /* undo busybox.c setlocale */ |
97 | setlocale(LC_NUMERIC, "C"); | 74 | setlocale(LC_NUMERIC, "C"); |
98 | # endif | 75 | # endif |
99 | duration = 0; | 76 | duration = 0; |
100 | do { | 77 | do { |
101 | char *arg = *argv; | 78 | duration += parse_duration_str(*argv); |
102 | if (strchr(arg, '.')) { | ||
103 | double d; | ||
104 | char *pp; | ||
105 | int len = strspn(arg, "0123456789."); | ||
106 | char sv = arg[len]; | ||
107 | arg[len] = '\0'; | ||
108 | errno = 0; | ||
109 | d = strtod(arg, &pp); | ||
110 | if (errno || *pp) | ||
111 | bb_show_usage(); | ||
112 | arg += len; | ||
113 | *arg-- = sv; | ||
114 | sv = *arg; | ||
115 | *arg = '1'; | ||
116 | duration += d * xatoul_sfx(arg, sfx); | ||
117 | *arg = sv; | ||
118 | } else { | ||
119 | duration += xatoul_sfx(arg, sfx); | ||
120 | } | ||
121 | } while (*++argv); | 79 | } while (*++argv); |
122 | 80 | sleep_for_duration(duration); | |
123 | ts.tv_sec = MAXINT(typeof(ts.tv_sec)); | ||
124 | ts.tv_nsec = 0; | ||
125 | if (duration >= 0 && duration < ts.tv_sec) { | ||
126 | ts.tv_sec = duration; | ||
127 | ts.tv_nsec = (duration - ts.tv_sec) * 1000000000; | ||
128 | } | ||
129 | do { | ||
130 | errno = 0; | ||
131 | nanosleep(&ts, &ts); | ||
132 | } while (errno == EINTR); | ||
133 | |||
134 | #elif ENABLE_FEATURE_FANCY_SLEEP | ||
135 | |||
136 | duration = 0; | ||
137 | do { | ||
138 | duration += xatou_range_sfx(*argv, 0, UINT_MAX - duration, sfx); | ||
139 | } while (*++argv); | ||
140 | sleep(duration); | ||
141 | |||
142 | #else /* simple */ | 81 | #else /* simple */ |
143 | |||
144 | duration = xatou(*argv); | 82 | duration = xatou(*argv); |
145 | sleep(duration); | 83 | sleep(duration); |
146 | // Off. If it's really needed, provide example why | ||
147 | //if (sleep(duration)) { | ||
148 | // bb_perror_nomsg_and_die(); | ||
149 | //} | ||
150 | |||
151 | #endif | 84 | #endif |
152 | |||
153 | return EXIT_SUCCESS; | 85 | return EXIT_SUCCESS; |
154 | } | 86 | } |
diff --git a/coreutils/timeout.c b/coreutils/timeout.c index c1be7b198..3b2140807 100644 --- a/coreutils/timeout.c +++ b/coreutils/timeout.c | |||
@@ -39,10 +39,10 @@ | |||
39 | //kbuild:lib-$(CONFIG_TIMEOUT) += timeout.o | 39 | //kbuild:lib-$(CONFIG_TIMEOUT) += timeout.o |
40 | 40 | ||
41 | //usage:#define timeout_trivial_usage | 41 | //usage:#define timeout_trivial_usage |
42 | //usage: "[-t SECS] [-s SIG] PROG ARGS" | 42 | //usage: "[-s SIG] SECS PROG ARGS" |
43 | //usage:#define timeout_full_usage "\n\n" | 43 | //usage:#define timeout_full_usage "\n\n" |
44 | //usage: "Runs PROG. Sends SIG to it if it is not gone in SECS seconds.\n" | 44 | //usage: "Runs PROG. Sends SIG to it if it is not gone in SECS seconds.\n" |
45 | //usage: "Defaults: SECS: 10, SIG: TERM." | 45 | //usage: "Default SIG: TERM." |
46 | 46 | ||
47 | #include "libbb.h" | 47 | #include "libbb.h" |
48 | 48 | ||
@@ -68,7 +68,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
68 | DWORD status = EXIT_SUCCESS; | 68 | DWORD status = EXIT_SUCCESS; |
69 | #endif | 69 | #endif |
70 | int parent = 0; | 70 | int parent = 0; |
71 | int timeout = 10; | 71 | int timeout; |
72 | pid_t pid; | 72 | pid_t pid; |
73 | #if !BB_MMU | 73 | #if !BB_MMU |
74 | char *sv1, *sv2; | 74 | char *sv1, *sv2; |
@@ -83,25 +83,34 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
83 | 83 | ||
84 | /* -t SECONDS; -p PARENT_PID */ | 84 | /* -t SECONDS; -p PARENT_PID */ |
85 | /* '+': stop at first non-option */ | 85 | /* '+': stop at first non-option */ |
86 | getopt32(argv, "+s:t:+" USE_FOR_NOMMU("p:+"), &opt_s, &timeout, &parent); | 86 | getopt32(argv, "+s:" USE_FOR_NOMMU("p:+"), &opt_s, &parent); |
87 | /*argv += optind; - no, wait for bb_daemonize_or_rexec! */ | 87 | /*argv += optind; - no, wait for bb_daemonize_or_rexec! */ |
88 | |||
88 | signo = get_signum(opt_s); | 89 | signo = get_signum(opt_s); |
89 | #if !ENABLE_PLATFORM_MINGW32 | 90 | #if !ENABLE_PLATFORM_MINGW32 |
90 | if (signo < 0) | 91 | if (signo < 0) |
92 | #else | ||
93 | if (signo != SIGTERM && signo != SIGKILL && signo != 0) | ||
94 | #endif | ||
91 | bb_error_msg_and_die("unknown signal '%s'", opt_s); | 95 | bb_error_msg_and_die("unknown signal '%s'", opt_s); |
92 | 96 | ||
97 | if (!argv[optind]) | ||
98 | bb_show_usage(); | ||
99 | timeout = parse_duration_str(argv[optind++]); | ||
100 | if (!argv[optind]) /* no PROG? */ | ||
101 | bb_show_usage(); | ||
102 | |||
103 | #if !ENABLE_PLATFORM_MINGW32 | ||
93 | /* We want to create a grandchild which will watch | 104 | /* We want to create a grandchild which will watch |
94 | * and kill the grandparent. Other methods: | 105 | * and kill the grandparent. Other methods: |
95 | * making parent watch child disrupts parent<->child link | 106 | * making parent watch child disrupts parent<->child link |
96 | * (example: "tcpsvd 0.0.0.0 1234 timeout service_prog" - | 107 | * (example: "tcpsvd 0.0.0.0 1234 timeout service_prog" - |
97 | * it's better if service_prog is a child of tcpsvd!), | 108 | * it's better if service_prog is a child of tcpsvd!), |
98 | * making child watch parent results in programs having | 109 | * making child watch parent results in programs having |
99 | * unexpected children. */ | 110 | * unexpected children. */ |
100 | 111 | ||
101 | if (parent) /* we were re-execed, already grandchild */ | 112 | if (parent) /* we were re-execed, already grandchild */ |
102 | goto grandchild; | 113 | goto grandchild; |
103 | if (!argv[optind]) /* no PROG? */ | ||
104 | bb_show_usage(); | ||
105 | 114 | ||
106 | #if !BB_MMU | 115 | #if !BB_MMU |
107 | sv1 = argv[optind]; | 116 | sv1 = argv[optind]; |
@@ -146,13 +155,6 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
146 | #endif | 155 | #endif |
147 | BB_EXECVP_or_die(argv); | 156 | BB_EXECVP_or_die(argv); |
148 | #else /* ENABLE_PLATFORM_MINGW32 */ | 157 | #else /* ENABLE_PLATFORM_MINGW32 */ |
149 | if (signo != SIGTERM && signo != SIGKILL && signo != 0) | ||
150 | bb_error_msg_and_die("unknown signal '%s'", opt_s); | ||
151 | |||
152 | argv += optind; | ||
153 | if (argv[0] == NULL) | ||
154 | bb_show_usage(); | ||
155 | |||
156 | if ((ret=mingw_spawn_proc((const char **)argv)) == -1) { | 158 | if ((ret=mingw_spawn_proc((const char **)argv)) == -1) { |
157 | xfunc_error_retval = errno == EACCES ? 126 : 127; | 159 | xfunc_error_retval = errno == EACCES ? 126 : 127; |
158 | bb_perror_msg_and_die("can't execute '%s'", argv[0]); | 160 | bb_perror_msg_and_die("can't execute '%s'", argv[0]); |