First commit
This commit is contained in:
49
init.c
Normal file
49
init.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/* 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;
|
||||
}
|
||||
Reference in New Issue
Block a user