50 lines
633 B
C
50 lines
633 B
C
/* See LICENSE file for copyright and license details. */
|
|
#include <signal.h>
|
|
#include <sys/wait.h>
|
|
#include <unistd.h>
|
|
|
|
void boot(void);
|
|
void shut(char);
|
|
|
|
int main(void)
|
|
{
|
|
int sig;
|
|
sigset_t set;
|
|
size_t i;
|
|
|
|
if (getpid() != 1)
|
|
return 1;
|
|
|
|
chdir("/");
|
|
|
|
sigfillset(&set);
|
|
sigprocmask(SIG_BLOCK, &set, NULL);
|
|
|
|
nice(15);
|
|
boot();
|
|
|
|
restart:
|
|
while (1)
|
|
{
|
|
sigwait(&set, &sig);
|
|
|
|
switch (sig)
|
|
{
|
|
case SIGUSR1:
|
|
shut('p');
|
|
goto restart;
|
|
case SIGCHLD:
|
|
case SIGALRM:
|
|
while (waitpid(-1, NULL, WNOHANG) > 0)
|
|
;
|
|
goto restart;
|
|
case SIGINT:
|
|
shut('r');
|
|
goto restart;
|
|
}
|
|
}
|
|
|
|
/* not reachable */
|
|
return 0;
|
|
}
|