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/timeout.c | |
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/timeout.c')
-rw-r--r-- | coreutils/timeout.c | 30 |
1 files changed, 16 insertions, 14 deletions
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]); |