reboot: signal init, add -f option to call reboot(); init: use SIGINT, use xsignal()
Now that oneit supports the same signals as our "sysv"-init for shutdown, make reboot et al. signal pid 1 with the appropriate signal. Of these signals, only SIGINT works with sysvinit 2.88, causing a reboot. The others are only supported in Busybox init. Also, make init accept SIGINT and use xsignal(). -- * I said init worked for me; that was with musl, where signal() is equivalent to xsignal(). With _XOPEN_SOURCE < 700 / on glibc, bsd_signal() is equivalent. * Behavior of sysvinit/shutdown/reboot/halt/poweroff: According to the manpage, reboot/shutdown/poweroff call shutdown(8) unless -f is passed. Reading the strace -f output, I'm not sure if that happens but it writes a 384-byte message to the /run/initctl fifo (formerly /dev/initctl). If you want to experiment on a sysvinit system, the simple way is to determine whether initctl is in /dev or /run; start a shell in a private mount namespace; mount -o bind,private an empty file over initctl; and then run the command you want, and use hd or such to examine the file. On sysvinit, only 3 signals do anything: SIGINT: reboot SIGPWR: read /etc/powerstatus, and take action based on content: 'O' - run "powerokwait" entries in inittab 'L' - run "powerfailnow" entries 'F'/default - run "powerwait" and "powerfail" entries. SIGSEGV: seems to basically stop polling initctl and wait for one of the three signals The manpage says to not use SIGPWR for new code. Thanks, Isaac Dunham
diff --git a/toys/other/reboot.c b/toys/other/reboot.c index 8baa4d8..8c1052a 100644 --- a/toys/other/reboot.c +++ b/toys/other/reboot.c @@ -2,7 +2,7 @@ * * Copyright 2013 Elie De Brauwer <[email protected]> -USE_REBOOT(NEWTOY(reboot, "n", TOYFLAG_BIN|TOYFLAG_NEEDROOT)) +USE_REBOOT(NEWTOY(reboot, "fn", TOYFLAG_BIN|TOYFLAG_NEEDROOT)) USE_REBOOT(OLDTOY(halt, reboot, TOYFLAG_BIN|TOYFLAG_NEEDROOT)) USE_REBOOT(OLDTOY(poweroff, reboot, TOYFLAG_BIN|TOYFLAG_NEEDROOT)) @@ -10,10 +10,11 @@ config REBOOT bool "reboot" default y help - usage: reboot/halt/poweroff [-n] + usage: reboot/halt/poweroff [-fn] Restart, halt or powerdown the system. + -f Don't signal init -n Don't sync before stopping the system. */ @@ -24,8 +25,12 @@ config REBOOT void reboot_main(void) { int types[] = {RB_AUTOBOOT, RB_HALT_SYSTEM, RB_POWER_OFF}; + int sigs[] = {SIGINT, SIGUSR1, SIGUSR2}; if (!(toys.optflags & FLAG_n)) sync(); - toys.exitval = reboot(types[stridx("hp", *toys.which->name)+1]); + if (toys.optflags & FLAG_f) + toys.exitval = reboot(types[stridx("hp", *toys.which->name)+1]); + else + toys.exitval = kill(1, sigs[stridx("hp", *toys.which->name)+1]); } diff --git a/toys/pending/init.c b/toys/pending/init.c index 529c1b9..8b3fbfc 100644 --- a/toys/pending/init.c +++ b/toys/pending/init.c @@ -348,6 +348,7 @@ static void halt_poweroff_reboot_handler(int sig_no) reboot_magic_no=RB_POWER_OFF; break; case SIGTERM: + case SIGINT: error_msg("Requesting system reboot"); reboot_magic_no=RB_AUTOBOOT; break; @@ -415,7 +416,7 @@ static void pause_handler(int sig_no) errno_backup = errno; signal_backup = caught_signal; - signal(SIGCONT, catch_signal); + xsignal(SIGCONT, catch_signal); while(1) { if (caught_signal == SIGCONT) break; @@ -460,10 +461,11 @@ void init_main(void) putenv("USER=root"); inittab_parsing(); - signal(SIGUSR1, halt_poweroff_reboot_handler);//halt - signal(SIGUSR2, halt_poweroff_reboot_handler);//poweroff - signal(SIGTERM, halt_poweroff_reboot_handler);//reboot - signal(SIGQUIT, restart_init_handler);//restart init + xsignal(SIGUSR1, halt_poweroff_reboot_handler);//halt + xsignal(SIGUSR2, halt_poweroff_reboot_handler);//poweroff + xsignal(SIGTERM, halt_poweroff_reboot_handler);//reboot + xsignal(SIGINT, halt_poweroff_reboot_handler);//reboot + xsignal(SIGQUIT, restart_init_handler);//restart init memset(&sig_act, 0, sizeof(sig_act)); sigfillset(&sig_act.sa_mask); sigdelset(&sig_act.sa_mask, SIGCONT);
_______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
