Implement power cycle in init.

If SIGWINCH is received, then halt with power cycle.

Sponsored by: Netflix
This commit is contained in:
Warner Losh 2017-10-25 15:30:40 +00:00
parent 7d7d9013f1
commit 35c1d16e3e
2 changed files with 5 additions and 3 deletions

View File

@ -286,6 +286,7 @@ as follows:
.It Sy "Run-level Signal Action"
.It Cm 0 Ta Dv SIGUSR1 Ta "Halt"
.It Cm 0 Ta Dv SIGUSR2 Ta "Halt and turn the power off"
.It Cm 0 Ta Dv SIGWINCH Ta "Halt and turn the power off and then back on"
.It Cm 1 Ta Dv SIGTERM Ta "Go to single-user mode"
.It Cm 6 Ta Dv SIGINT Ta "Reboot the machine"
.It Cm c Ta Dv SIGTSTP Ta "Block further logins"

View File

@ -305,12 +305,12 @@ main(int argc, char *argv[])
handle(disaster, SIGABRT, SIGFPE, SIGILL, SIGSEGV, SIGBUS, SIGXCPU,
SIGXFSZ, 0);
handle(transition_handler, SIGHUP, SIGINT, SIGEMT, SIGTERM, SIGTSTP,
SIGUSR1, SIGUSR2, 0);
SIGUSR1, SIGUSR2, SIGWINCH, 0);
handle(alrm_handler, SIGALRM, 0);
sigfillset(&mask);
delset(&mask, SIGABRT, SIGFPE, SIGILL, SIGSEGV, SIGBUS, SIGSYS,
SIGXCPU, SIGXFSZ, SIGHUP, SIGINT, SIGEMT, SIGTERM, SIGTSTP,
SIGALRM, SIGUSR1, SIGUSR2, 0);
SIGALRM, SIGUSR1, SIGUSR2, SIGWINCH, 0);
sigprocmask(SIG_SETMASK, &mask, (sigset_t *) 0);
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
@ -1557,8 +1557,9 @@ transition_handler(int sig)
current_state == clean_ttys || current_state == catatonia)
requested_transition = clean_ttys;
break;
case SIGWINCH:
case SIGUSR2:
howto = RB_POWEROFF;
howto = sig == SIGUSR2 ? RB_POWEROFF : RB_POWERCYCLE;
case SIGUSR1:
howto |= RB_HALT;
case SIGINT: