diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-06 22:39:57 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-06 22:39:57 +0000 |
| commit | 3854c5ddf4eb267e4e53796eaa1051421dcb4e08 (patch) | |
| tree | 7110eecec665bc64fefcdedaa29eb2e2fdf2df41 /runit | |
| parent | 70e8f49f71b824bbc7c5ec825eb33108134d1ee5 (diff) | |
| download | busybox-w32-3854c5ddf4eb267e4e53796eaa1051421dcb4e08.tar.gz busybox-w32-3854c5ddf4eb267e4e53796eaa1051421dcb4e08.tar.bz2 busybox-w32-3854c5ddf4eb267e4e53796eaa1051421dcb4e08.zip | |
runsvdir: alternative methon of supporting runsvdir-as-init. +66 bytes.
*: s/int/pid_t where appropriate
Diffstat (limited to 'runit')
| -rw-r--r-- | runit/runsv.c | 4 | ||||
| -rw-r--r-- | runit/runsvdir.c | 54 | ||||
| -rw-r--r-- | runit/svlogd.c | 3 |
3 files changed, 37 insertions, 24 deletions
diff --git a/runit/runsv.c b/runit/runsv.c index bd0f3dcc2..56244d03f 100644 --- a/runit/runsv.c +++ b/runit/runsv.c | |||
| @@ -247,7 +247,7 @@ static void update_status(struct svdir *s) | |||
| 247 | 247 | ||
| 248 | static unsigned custom(struct svdir *s, char c) | 248 | static unsigned custom(struct svdir *s, char c) |
| 249 | { | 249 | { |
| 250 | int pid; | 250 | pid_t pid; |
| 251 | int w; | 251 | int w; |
| 252 | char a[10]; | 252 | char a[10]; |
| 253 | struct stat st; | 253 | struct stat st; |
| @@ -584,7 +584,7 @@ int runsv_main(int argc UNUSED_PARAM, char **argv) | |||
| 584 | continue; | 584 | continue; |
| 585 | 585 | ||
| 586 | for (;;) { | 586 | for (;;) { |
| 587 | int child; | 587 | pid_t child; |
| 588 | int wstat; | 588 | int wstat; |
| 589 | 589 | ||
| 590 | child = wait_any_nohang(&wstat); | 590 | child = wait_any_nohang(&wstat); |
diff --git a/runit/runsvdir.c b/runit/runsvdir.c index 581787f03..9d560e097 100644 --- a/runit/runsvdir.c +++ b/runit/runsvdir.c | |||
| @@ -107,7 +107,7 @@ static NOINLINE pid_t runsv(const char *name) | |||
| 107 | } | 107 | } |
| 108 | if (pid == 0) { | 108 | if (pid == 0) { |
| 109 | /* child */ | 109 | /* child */ |
| 110 | if (option_mask32) /* -P option? */ | 110 | if (option_mask32 & 1) /* -P option? */ |
| 111 | setsid(); | 111 | setsid(); |
| 112 | /* man execv: | 112 | /* man execv: |
| 113 | * "Signals set to be caught by the calling process image | 113 | * "Signals set to be caught by the calling process image |
| @@ -217,17 +217,20 @@ int runsvdir_main(int argc UNUSED_PARAM, char **argv) | |||
| 217 | time_t last_mtime = 0; | 217 | time_t last_mtime = 0; |
| 218 | int wstat; | 218 | int wstat; |
| 219 | int curdir; | 219 | int curdir; |
| 220 | int pid; | 220 | pid_t pid; |
| 221 | unsigned deadline; | 221 | unsigned deadline; |
| 222 | unsigned now; | 222 | unsigned now; |
| 223 | unsigned stampcheck; | 223 | unsigned stampcheck; |
| 224 | int i; | 224 | int i; |
| 225 | int need_rescan = 1; | 225 | int need_rescan = 1; |
| 226 | char *opt_s_argv[3]; | ||
| 226 | 227 | ||
| 227 | INIT_G(); | 228 | INIT_G(); |
| 228 | 229 | ||
| 229 | opt_complementary = "-1"; | 230 | opt_complementary = "-1"; |
| 230 | getopt32(argv, "P"); | 231 | opt_s_argv[0] = NULL; |
| 232 | opt_s_argv[2] = NULL; | ||
| 233 | getopt32(argv, "Ps:", &opt_s_argv[0]); | ||
| 231 | argv += optind; | 234 | argv += optind; |
| 232 | 235 | ||
| 233 | bb_signals(0 | 236 | bb_signals(0 |
| @@ -335,7 +338,6 @@ int runsvdir_main(int argc UNUSED_PARAM, char **argv) | |||
| 335 | pfd[0].revents = 0; | 338 | pfd[0].revents = 0; |
| 336 | #endif | 339 | #endif |
| 337 | deadline = (need_rescan ? 1 : 5); | 340 | deadline = (need_rescan ? 1 : 5); |
| 338 | do_sleep: | ||
| 339 | sig_block(SIGCHLD); | 341 | sig_block(SIGCHLD); |
| 340 | #if ENABLE_FEATURE_RUNSVDIR_LOG | 342 | #if ENABLE_FEATURE_RUNSVDIR_LOG |
| 341 | if (rplog) | 343 | if (rplog) |
| @@ -357,27 +359,37 @@ int runsvdir_main(int argc UNUSED_PARAM, char **argv) | |||
| 357 | } | 359 | } |
| 358 | } | 360 | } |
| 359 | #endif | 361 | #endif |
| 362 | if (!bb_got_signal) | ||
| 363 | continue; | ||
| 364 | |||
| 365 | /* -s SCRIPT: useful if we are init. | ||
| 366 | * In this case typically script never returns, | ||
| 367 | * it halts/powers off/reboots the system. */ | ||
| 368 | if (opt_s_argv[0]) { | ||
| 369 | /* Single parameter: signal# */ | ||
| 370 | opt_s_argv[1] = utoa(bb_got_signal); | ||
| 371 | pid = spawn(opt_s_argv); | ||
| 372 | if (pid > 0) { | ||
| 373 | /* Remebering to wait for _any_ children, | ||
| 374 | * not just pid */ | ||
| 375 | while (wait(NULL) != pid) | ||
| 376 | continue; | ||
| 377 | } | ||
| 378 | } | ||
| 379 | |||
| 360 | switch (bb_got_signal) { | 380 | switch (bb_got_signal) { |
| 361 | case 0: /* we are not signaled, business as usual */ | ||
| 362 | break; | ||
| 363 | case SIGHUP: | 381 | case SIGHUP: |
| 364 | for (i = 0; i < svnum; i++) | 382 | for (i = 0; i < svnum; i++) |
| 365 | if (sv[i].pid) | 383 | if (sv[i].pid) |
| 366 | kill(sv[i].pid, SIGTERM); | 384 | kill(sv[i].pid, SIGTERM); |
| 367 | /* fall through */ | 385 | /* Fall through */ |
| 368 | case SIGTERM: | 386 | default: /* SIGTERM (or SIGUSRn if we are init) */ |
| 369 | /* exit, unless we are init */ | 387 | /* Exit unless we are init */ |
| 370 | if (getpid() != 1) | 388 | if (getpid() == 1) |
| 371 | goto ret; | 389 | break; |
| 372 | default: | 390 | return (SIGHUP == bb_got_signal) ? 111 : EXIT_SUCCESS; |
| 373 | /* so we are init. do not exit, | ||
| 374 | * and pause respawning - we may be rebooting | ||
| 375 | * (but SIGHUP is not a reboot, make short pause) */ | ||
| 376 | deadline = (SIGHUP == bb_got_signal) ? 5 : 60; | ||
| 377 | bb_got_signal = 0; | ||
| 378 | goto do_sleep; | ||
| 379 | } | 391 | } |
| 380 | } | 392 | |
| 381 | ret: | 393 | bb_got_signal = 0; |
| 382 | return (SIGHUP == bb_got_signal) ? 111 : EXIT_SUCCESS; | 394 | } /* for (;;) */ |
| 383 | } | 395 | } |
diff --git a/runit/svlogd.c b/runit/svlogd.c index 960879513..64191281e 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c | |||
| @@ -797,7 +797,8 @@ static void sig_term_handler(int sig_no UNUSED_PARAM) | |||
| 797 | 797 | ||
| 798 | static void sig_child_handler(int sig_no UNUSED_PARAM) | 798 | static void sig_child_handler(int sig_no UNUSED_PARAM) |
| 799 | { | 799 | { |
| 800 | int pid, l; | 800 | pid_t pid; |
| 801 | int l; | ||
| 801 | 802 | ||
| 802 | if (verbose) | 803 | if (verbose) |
| 803 | bb_error_msg(INFO"sig%s received", "child"); | 804 | bb_error_msg(INFO"sig%s received", "child"); |
