39
39
//kbuild:lib-$(CONFIG_TIMEOUT) += timeout.o
40
40
41
41
//usage:#define timeout_trivial_usage
42
- //usage: "[-t SECS] [- s SIG] PROG ARGS"
42
+ //usage: "[-s SIG] SECS PROG ARGS"
43
43
//usage:#define timeout_full_usage "\n\n"
44
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
47
#include "libbb.h"
48
48
@@ -52,8 +52,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
52
52
int signo ;
53
53
int status ;
54
54
int parent = 0 ;
55
- unsigned timeout ;
56
- const char * timeout_s = "10" ;
55
+ int timeout ;
57
56
pid_t pid ;
58
57
#if !BB_MMU
59
58
char * sv1 , * sv2 ;
@@ -64,25 +63,29 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
64
63
65
64
/* -t SECONDS; -p PARENT_PID */
66
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
67
/*argv += optind; - no, wait for bb_daemonize_or_rexec! */
68
+
69
69
signo = get_signum (opt_s );
70
70
if (signo < 0 )
71
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
79
/* We want to create a grandchild which will watch
75
80
* and kill the grandparent. Other methods:
76
81
* making parent watch child disrupts parent<->child link
77
82
* (example: "tcpsvd 0.0.0.0 1234 timeout service_prog" -
78
83
* it's better if service_prog is a child of tcpsvd!),
79
84
* making child watch parent results in programs having
80
- * unexpected children. */
85
+ * unexpected children. */
81
86
82
87
if (parent ) /* we were re-execed, already grandchild */
83
88
goto grandchild ;
84
- if (!argv [optind ]) /* no PROG? */
85
- bb_show_usage ();
86
89
87
90
#if !BB_MMU
88
91
sv1 = argv [optind ];
0 commit comments