diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-08-03 18:27:00 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-08-03 18:28:17 +0200 |
commit | c9720a761e88e83265b4d75808533cdfbc66075b (patch) | |
tree | 909199889dd3668f4699c07c70410fc182a3d4a7 | |
parent | 4c20d9f2b0223874e2b5ac1235d5f33fdd02589b (diff) | |
download | busybox-w32-c9720a761e88e83265b4d75808533cdfbc66075b.tar.gz busybox-w32-c9720a761e88e83265b4d75808533cdfbc66075b.tar.bz2 busybox-w32-c9720a761e88e83265b4d75808533cdfbc66075b.zip |
timeout: fix arguments to match coreutils
Was: timeout [-t SECS] [-s SIG] PROG ARGS
Is: timeout [-s SIG] SECS PROG ARGS
function old new delta
timeout_main 312 319 +7
packed_usage 32882 32858 -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 7/-24) Total: -17 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/timeout.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/coreutils/timeout.c b/coreutils/timeout.c index 663303c2d..e42aba85c 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 | ||
@@ -52,8 +52,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
52 | int signo; | 52 | int signo; |
53 | int status; | 53 | int status; |
54 | int parent = 0; | 54 | int parent = 0; |
55 | unsigned timeout; | 55 | int timeout; |
56 | const char *timeout_s = "10"; | ||
57 | pid_t pid; | 56 | pid_t pid; |
58 | #if !BB_MMU | 57 | #if !BB_MMU |
59 | char *sv1, *sv2; | 58 | char *sv1, *sv2; |
@@ -64,12 +63,18 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
64 | 63 | ||
65 | /* -t SECONDS; -p PARENT_PID */ | 64 | /* -t SECONDS; -p PARENT_PID */ |
66 | /* '+': stop at first non-option */ | 65 | /* '+': stop at first non-option */ |
67 | getopt32(argv, "+s:t:" USE_FOR_NOMMU("p:+"), &opt_s, &timeout_s, &parent); | 66 | getopt32(argv, "+s:" USE_FOR_NOMMU("p:+"), &opt_s, &parent); |
68 | /*argv += optind; - no, wait for bb_daemonize_or_rexec! */ | 67 | /*argv += optind; - no, wait for bb_daemonize_or_rexec! */ |
68 | |||
69 | signo = get_signum(opt_s); | 69 | signo = get_signum(opt_s); |
70 | if (signo < 0) | 70 | if (signo < 0) |
71 | bb_error_msg_and_die("unknown signal '%s'", opt_s); | 71 | bb_error_msg_and_die("unknown signal '%s'", opt_s); |
72 | timeout = parse_duration_str((char*)timeout_s); | 72 | |
73 | if (!argv[optind]) | ||
74 | bb_show_usage(); | ||
75 | timeout = parse_duration_str(argv[optind++]); | ||
76 | if (!argv[optind]) /* no PROG? */ | ||
77 | bb_show_usage(); | ||
73 | 78 | ||
74 | /* We want to create a grandchild which will watch | 79 | /* We want to create a grandchild which will watch |
75 | * and kill the grandparent. Other methods: | 80 | * and kill the grandparent. Other methods: |
@@ -77,12 +82,10 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
77 | * (example: "tcpsvd 0.0.0.0 1234 timeout service_prog" - | 82 | * (example: "tcpsvd 0.0.0.0 1234 timeout service_prog" - |
78 | * it's better if service_prog is a child of tcpsvd!), | 83 | * it's better if service_prog is a child of tcpsvd!), |
79 | * making child watch parent results in programs having | 84 | * making child watch parent results in programs having |
80 | * unexpected children. */ | 85 | * unexpected children. */ |
81 | 86 | ||
82 | if (parent) /* we were re-execed, already grandchild */ | 87 | if (parent) /* we were re-execed, already grandchild */ |
83 | goto grandchild; | 88 | goto grandchild; |
84 | if (!argv[optind]) /* no PROG? */ | ||
85 | bb_show_usage(); | ||
86 | 89 | ||
87 | #if !BB_MMU | 90 | #if !BB_MMU |
88 | sv1 = argv[optind]; | 91 | sv1 = argv[optind]; |