aboutsummaryrefslogtreecommitdiff
path: root/runit
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-06-07 11:34:06 +0100
committerRon Yorston <rmy@pobox.com>2021-06-07 11:34:06 +0100
commitabe872e2a0342357a5608342cb2892e94027b3e7 (patch)
tree297cdccf332fbb5e4eb31b1eac643180059f9b5f /runit
parent1f33f42d7bcb019b268d938df643a7a785dc19ab (diff)
parent4d983dcddeee94892d3072e84c7c9a01d4696055 (diff)
downloadbusybox-w32-abe872e2a0342357a5608342cb2892e94027b3e7.tar.gz
busybox-w32-abe872e2a0342357a5608342cb2892e94027b3e7.tar.bz2
busybox-w32-abe872e2a0342357a5608342cb2892e94027b3e7.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'runit')
-rw-r--r--runit/runsv.c39
-rw-r--r--runit/svlogd.c31
2 files changed, 47 insertions, 23 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
diff --git a/runit/svlogd.c b/runit/svlogd.c
index 294e31aca..02c305696 100644
--- a/runit/svlogd.c
+++ b/runit/svlogd.c
@@ -412,19 +412,32 @@ static void processorstart(struct logdir *ld)
412 int fd; 412 int fd;
413 413
414 /* child */ 414 /* child */
415 /* Non-ignored signals revert to SIG_DFL on exec anyway */ 415 /* Non-ignored signals revert to SIG_DFL on exec anyway.
416 * But we can get signals BEFORE execl(), this is unlikely
417 * but wouldn't be good...
418 */
416 /*bb_signals(0 419 /*bb_signals(0
417 + (1 << SIGTERM) 420 + (1 << SIGTERM)
421 //+ (1 << SIGCHLD)
418 + (1 << SIGALRM) 422 + (1 << SIGALRM)
419 + (1 << SIGHUP) 423 + (1 << SIGHUP)
420 , SIG_DFL);*/ 424 , SIG_DFL);*/
421 sig_unblock(SIGTERM); 425 /* runit 2.1.2 does not unblock SIGCHLD, a bug? we do: */
422 sig_unblock(SIGALRM); 426 sigprocmask(SIG_UNBLOCK, &blocked_sigset, NULL);
423 sig_unblock(SIGHUP);
424 427
425 if (verbose) 428 if (verbose)
426 bb_error_msg(INFO"processing: %s/%s", ld->name, ld->fnsave); 429 bb_error_msg(INFO"processing: %s/%s", ld->name, ld->fnsave);
427 fd = xopen(ld->fnsave, O_RDONLY|O_NDELAY); 430
431 fd = open_or_warn(ld->fnsave, O_RDONLY|O_NDELAY);
432 /* Used to have xopen() above, but it causes infinite restarts of processor
433 * if file is gone - which can happen even because of _us_!
434 * Users report that if on reboot, time is reset to before existing
435 * logfiles creation time, rmoldest() deletes the newest logfile (!)
436 * and we end up here trying to open this now-deleted file.
437 */
438 if (fd < 0)
439 _exit(0); /* fake "success": do not run processor again */
440
428 xmove_fd(fd, 0); 441 xmove_fd(fd, 0);
429 ld->fnsave[26] = 't'; /* <- that's why we need sv_ch! */ 442 ld->fnsave[26] = 't'; /* <- that's why we need sv_ch! */
430 fd = xopen(ld->fnsave, O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT); 443 fd = xopen(ld->fnsave, O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT);
@@ -1098,10 +1111,10 @@ int svlogd_main(int argc, char **argv)
1098 sigaddset(&blocked_sigset, SIGALRM); 1111 sigaddset(&blocked_sigset, SIGALRM);
1099 sigaddset(&blocked_sigset, SIGHUP); 1112 sigaddset(&blocked_sigset, SIGHUP);
1100 sigprocmask(SIG_BLOCK, &blocked_sigset, NULL); 1113 sigprocmask(SIG_BLOCK, &blocked_sigset, NULL);
1101 bb_signals_recursive_norestart(1 << SIGTERM, sig_term_handler); 1114 bb_signals_norestart(1 << SIGTERM, sig_term_handler);
1102 bb_signals_recursive_norestart(1 << SIGCHLD, sig_child_handler); 1115 bb_signals_norestart(1 << SIGCHLD, sig_child_handler);
1103 bb_signals_recursive_norestart(1 << SIGALRM, sig_alarm_handler); 1116 bb_signals_norestart(1 << SIGALRM, sig_alarm_handler);
1104 bb_signals_recursive_norestart(1 << SIGHUP, sig_hangup_handler); 1117 bb_signals_norestart(1 << SIGHUP, sig_hangup_handler);
1105 1118
1106 /* Without timestamps, we don't have to print each line 1119 /* Without timestamps, we don't have to print each line
1107 * separately, so we can look for _last_ newline, not first, 1120 * separately, so we can look for _last_ newline, not first,