diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-07 01:39:57 +0300 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-07 01:39:57 +0300 |
commit | 3854c5ddf4eb267e4e53796eaa1051421dcb4e08 (patch) | |
tree | 7110eecec665bc64fefcdedaa29eb2e2fdf2df41 /runit | |
parent | 70e8f49f71b824bbc7c5ec825eb33108134d1ee5 (diff) |
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) static unsigned custom(struct svdir *s, char c) { - int pid; + pid_t pid; int w; char a[10]; struct stat st; @@ -584,7 +584,7 @@ int runsv_main(int argc UNUSED_PARAM, char **argv) continue; for (;;) { - int child; + pid_t child; int wstat; 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) } if (pid == 0) { /* child */ - if (option_mask32) /* -P option? */ + if (option_mask32 & 1) /* -P option? */ setsid(); /* man execv: * "Signals set to be caught by the calling process image @@ -217,17 +217,20 @@ int runsvdir_main(int argc UNUSED_PARAM, char **argv) time_t last_mtime = 0; int wstat; int curdir; - int pid; + pid_t pid; unsigned deadline; unsigned now; unsigned stampcheck; int i; int need_rescan = 1; + char *opt_s_argv[3]; INIT_G(); opt_complementary = "-1"; - getopt32(argv, "P"); + opt_s_argv[0] = NULL; + opt_s_argv[2] = NULL; + getopt32(argv, "Ps:", &opt_s_argv[0]); argv += optind; bb_signals(0 @@ -335,7 +338,6 @@ int runsvdir_main(int argc UNUSED_PARAM, char **argv) pfd[0].revents = 0; #endif deadline = (need_rescan ? 1 : 5); - do_sleep: sig_block(SIGCHLD); #if ENABLE_FEATURE_RUNSVDIR_LOG if (rplog) @@ -357,27 +359,37 @@ int runsvdir_main(int argc UNUSED_PARAM, char **argv) } } #endif + if (!bb_got_signal) + continue; + + /* -s SCRIPT: useful if we are init. + * In this case typically script never returns, + * it halts/powers off/reboots the system. */ + if (opt_s_argv[0]) { + /* Single parameter: signal# */ + opt_s_argv[1] = utoa(bb_got_signal); + pid = spawn(opt_s_argv); + if (pid > 0) { + /* Remebering to wait for _any_ children, + * not just pid */ + while (wait(NULL) != pid) + continue; + } + } + switch (bb_got_signal) { - case 0: /* we are not signaled, business as usual */ - break; case SIGHUP: for (i = 0; i < svnum; i++) if (sv[i].pid) kill(sv[i].pid, SIGTERM); - /* fall through */ - case SIGTERM: - /* exit, unless we are init */ - if (getpid() != 1) - goto ret; - default: - /* so we are init. do not exit, - * and pause respawning - we may be rebooting - * (but SIGHUP is not a reboot, make short pause) */ - deadline = (SIGHUP == bb_got_signal) ? 5 : 60; - bb_got_signal = 0; - goto do_sleep; + /* Fall through */ + default: /* SIGTERM (or SIGUSRn if we are init) */ + /* Exit unless we are init */ + if (getpid() == 1) + break; + return (SIGHUP == bb_got_signal) ? 111 : EXIT_SUCCESS; } - } - ret: - return (SIGHUP == bb_got_signal) ? 111 : EXIT_SUCCESS; + + bb_got_signal = 0; + } /* for (;;) */ } 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) static void sig_child_handler(int sig_no UNUSED_PARAM) { - int pid, l; + pid_t pid; + int l; if (verbose) bb_error_msg(INFO"sig%s received", "child"); |