aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-10-29 03:42:44 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-10-29 03:42:44 +0000
commit9657596dd6e9f066082bcf7056412fe1411fa0ef (patch)
tree7b6aa5fcd4a520e3d95870bd49a8f17bea70eff0
parent40fdcbb2700a2fe54b184aa9fdf4ed55d23df081 (diff)
downloadbusybox-w32-9657596dd6e9f066082bcf7056412fe1411fa0ef.tar.gz
busybox-w32-9657596dd6e9f066082bcf7056412fe1411fa0ef.tar.bz2
busybox-w32-9657596dd6e9f066082bcf7056412fe1411fa0ef.zip
runsvdir: do not exit if we are pid 1.
-rw-r--r--runit/runsvdir.c55
1 files changed, 41 insertions, 14 deletions
diff --git a/runit/runsvdir.c b/runit/runsvdir.c
index 8099ebf5c..d37eaf548 100644
--- a/runit/runsvdir.c
+++ b/runit/runsvdir.c
@@ -115,10 +115,16 @@ static void runsv(int no, const char *name)
115 /* child */ 115 /* child */
116 if (set_pgrp) 116 if (set_pgrp)
117 setsid(); 117 setsid();
118/* man execv:
119 * Signals set to be caught by the calling process image
120 * shall be set to the default action in the new process image.
121 * Therefore, we do not need this: */
122#if 0
118 bb_signals(0 123 bb_signals(0
119 + (1 << SIGHUP) 124 | (1 << SIGHUP)
120 + (1 << SIGTERM) 125 | (1 << SIGTERM)
121 , SIG_DFL); 126 , SIG_DFL);
127#endif
122 execvp(prog[0], prog); 128 execvp(prog[0], prog);
123 fatal2_cannot("start runsv ", name); 129 fatal2_cannot("start runsv ", name);
124 } 130 }
@@ -227,7 +233,19 @@ int runsvdir_main(int argc UNUSED_PARAM, char **argv)
227 set_pgrp = getopt32(argv, "P"); 233 set_pgrp = getopt32(argv, "P");
228 argv += optind; 234 argv += optind;
229 235
230 bb_signals_recursive((1 << SIGTERM) | (1 << SIGHUP), record_signo); 236 bb_signals(0
237 | (1 << SIGTERM)
238 | (1 << SIGHUP)
239 /* For busybox's init, SIGTERM == reboot,
240 * SIGUSR1 == halt
241 * SIGUSR2 == poweroff
242 * so we need to intercept SIGUSRn too.
243 * Note that we do not implement actual reboot
244 * (killall(TERM) + umount, etc), we just pause
245 * respawing and avoid exiting (-> making kernel oops).
246 * The user is responsible for the rest. */
247 | (getpid() == 1 ? ((1 << SIGUSR1) | (1 << SIGUSR2)) : 0)
248 , record_signo);
231 svdir = *argv++; 249 svdir = *argv++;
232 250
233#if ENABLE_FEATURE_RUNSVDIR_LOG 251#if ENABLE_FEATURE_RUNSVDIR_LOG
@@ -256,7 +274,7 @@ int runsvdir_main(int argc UNUSED_PARAM, char **argv)
256 rplog = NULL; 274 rplog = NULL;
257 warnx("log service disabled"); 275 warnx("log service disabled");
258 } 276 }
259run: 277 run:
260#endif 278#endif
261 curdir = open_read("."); 279 curdir = open_read(".");
262 if (curdir == -1) 280 if (curdir == -1)
@@ -319,8 +337,9 @@ run:
319 } 337 }
320 pfd[0].revents = 0; 338 pfd[0].revents = 0;
321#endif 339#endif
322 sig_block(SIGCHLD);
323 deadline = (need_rescan ? 1 : 5); 340 deadline = (need_rescan ? 1 : 5);
341 do_sleep:
342 sig_block(SIGCHLD);
324#if ENABLE_FEATURE_RUNSVDIR_LOG 343#if ENABLE_FEATURE_RUNSVDIR_LOG
325 if (rplog) 344 if (rplog)
326 poll(pfd, 1, deadline*1000); 345 poll(pfd, 1, deadline*1000);
@@ -333,11 +352,11 @@ run:
333 if (pfd[0].revents & POLLIN) { 352 if (pfd[0].revents & POLLIN) {
334 char ch; 353 char ch;
335 while (read(logpipe.rd, &ch, 1) > 0) { 354 while (read(logpipe.rd, &ch, 1) > 0) {
336 if (ch) { 355 if (ch < ' ')
337 for (i = 6; i < rploglen; i++) 356 ch = ' ';
338 rplog[i-1] = rplog[i]; 357 for (i = 6; i < rploglen; i++)
339 rplog[rploglen-1] = ch; 358 rplog[i-1] = rplog[i];
340 } 359 rplog[rploglen-1] = ch;
341 } 360 }
342 } 361 }
343#endif 362#endif
@@ -346,11 +365,19 @@ run:
346 for (i = 0; i < svnum; i++) 365 for (i = 0; i < svnum; i++)
347 if (sv[i].pid) 366 if (sv[i].pid)
348 kill(sv[i].pid, SIGTERM); 367 kill(sv[i].pid, SIGTERM);
349 // N.B. fall through 368 /* fall through */
350 case SIGTERM: 369 case SIGTERM:
351 _exit((SIGHUP == bb_got_signal) ? 111 : EXIT_SUCCESS); 370 /* exit, unless we are init */
371 if (getpid() != 1)
372 goto ret;
373 default:
374 /* so we are init. do not exit,
375 * and pause respawning - we may be rebooting... */
376 bb_got_signal = 0;
377 deadline = 60;
378 goto do_sleep;
352 } 379 }
353 } 380 }
354 /* not reached */ 381 ret:
355 return 0; 382 return (SIGHUP == bb_got_signal) ? 111 : EXIT_SUCCESS;
356} 383}