aboutsummaryrefslogtreecommitdiff
path: root/runit/runsv.c
diff options
context:
space:
mode:
Diffstat (limited to 'runit/runsv.c')
-rw-r--r--runit/runsv.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/runit/runsv.c b/runit/runsv.c
index ecab8cdf5..a4b8af494 100644
--- a/runit/runsv.c
+++ b/runit/runsv.c
@@ -149,17 +149,18 @@ static void warn_cannot(const char *m)
149 warn2_cannot(m, ""); 149 warn2_cannot(m, "");
150} 150}
151 151
152static void s_child(int sig_no UNUSED_PARAM) 152/* SIGCHLD/TERM handler is reentrancy-safe because they are unmasked
153 * only over poll() call, not over memory allocations
154 * or printouts. Do not need to save/restore errno either,
155 * as poll() error is not checked there.
156 */
157static void s_chld_term(int sig_no)
153{ 158{
159 if (sig_no == SIGTERM)
160 sigterm = 1;
154 write(selfpipe.wr, "", 1); 161 write(selfpipe.wr, "", 1);
155} 162}
156 163
157static void s_term(int sig_no UNUSED_PARAM)
158{
159 sigterm = 1;
160 write(selfpipe.wr, "", 1); /* XXX */
161}
162
163static int open_trunc_or_warn(const char *name) 164static int open_trunc_or_warn(const char *name)
164{ 165{
165 /* Why O_NDELAY? */ 166 /* Why O_NDELAY? */
@@ -380,11 +381,14 @@ static void startservice(struct svdir *s)
380 xdup2(logpipe.wr, 1); 381 xdup2(logpipe.wr, 1);
381 } 382 }
382 } 383 }
383 /* Non-ignored signals revert to SIG_DFL on exec anyway */ 384 /* Non-ignored signals revert to SIG_DFL on exec.
384 /*bb_signals(0 385 * But we can get signals BEFORE execl(), unlikely as that may be.
385 + (1 << SIGCHLD) 386 * SIGCHLD is safe (would merely write to selfpipe),
386 + (1 << SIGTERM) 387 * but SIGTERM would set sigterm = 1 (with vfork, we affect parent).
387 , SIG_DFL);*/ 388 * Avoid that.
389 */
390 /*signal(SIGCHLD, SIG_DFL);*/
391 signal(SIGTERM, SIG_DFL);
388 sig_unblock(SIGCHLD); 392 sig_unblock(SIGCHLD);
389 sig_unblock(SIGTERM); 393 sig_unblock(SIGTERM);
390 execv(arg[0], (char**) arg); 394 execv(arg[0], (char**) arg);
@@ -511,9 +515,15 @@ int runsv_main(int argc UNUSED_PARAM, char **argv)
511 ndelay_on(selfpipe.wr); 515 ndelay_on(selfpipe.wr);
512 516
513 sig_block(SIGCHLD); 517 sig_block(SIGCHLD);
514 bb_signals_recursive_norestart(1 << SIGCHLD, s_child);
515 sig_block(SIGTERM); 518 sig_block(SIGTERM);
516 bb_signals_recursive_norestart(1 << SIGTERM, s_term); 519 /* No particular reason why we don't set SA_RESTART
520 * (poll() wouldn't restart regardless of that flag),
521 * we just follow what runit-2.1.2 does:
522 */
523 bb_signals_norestart(0
524 + (1 << SIGCHLD)
525 + (1 << SIGTERM)
526 , s_chld_term);
517 527
518 xchdir(dir); 528 xchdir(dir);
519 /* bss: svd[0].pid = 0; */ 529 /* bss: svd[0].pid = 0; */
@@ -625,6 +635,7 @@ int runsv_main(int argc UNUSED_PARAM, char **argv)
625 sig_unblock(SIGTERM); 635 sig_unblock(SIGTERM);
626 sig_unblock(SIGCHLD); 636 sig_unblock(SIGCHLD);
627 poll(x, 2 + haslog, 3600*1000); 637 poll(x, 2 + haslog, 3600*1000);
638 /* NB: signal handlers can trash errno of poll() */
628 sig_block(SIGTERM); 639 sig_block(SIGTERM);
629 sig_block(SIGCHLD); 640 sig_block(SIGCHLD);
630 641