Skip to content

Commit c9720a7

Browse files
author
Denys Vlasenko
committed
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>
1 parent 4c20d9f commit c9720a7

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

coreutils/timeout.c

+12-9
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
//kbuild:lib-$(CONFIG_TIMEOUT) += timeout.o
4040

4141
//usage:#define timeout_trivial_usage
42-
//usage: "[-t SECS] [-s SIG] PROG ARGS"
42+
//usage: "[-s SIG] SECS PROG ARGS"
4343
//usage:#define timeout_full_usage "\n\n"
4444
//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."
4646

4747
#include "libbb.h"
4848

@@ -52,8 +52,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
5252
int signo;
5353
int status;
5454
int parent = 0;
55-
unsigned timeout;
56-
const char *timeout_s = "10";
55+
int timeout;
5756
pid_t pid;
5857
#if !BB_MMU
5958
char *sv1, *sv2;
@@ -64,25 +63,29 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
6463

6564
/* -t SECONDS; -p PARENT_PID */
6665
/* '+': 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);
6867
/*argv += optind; - no, wait for bb_daemonize_or_rexec! */
68+
6969
signo = get_signum(opt_s);
7070
if (signo < 0)
7171
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();
7378

7479
/* We want to create a grandchild which will watch
7580
* and kill the grandparent. Other methods:
7681
* making parent watch child disrupts parent<->child link
7782
* (example: "tcpsvd 0.0.0.0 1234 timeout service_prog" -
7883
* it's better if service_prog is a child of tcpsvd!),
7984
* making child watch parent results in programs having
80-
* unexpected children. */
85+
* unexpected children. */
8186

8287
if (parent) /* we were re-execed, already grandchild */
8388
goto grandchild;
84-
if (!argv[optind]) /* no PROG? */
85-
bb_show_usage();
8689

8790
#if !BB_MMU
8891
sv1 = argv[optind];

0 commit comments

Comments
 (0)