First commit

This commit is contained in:
PedroEdiaz
2025-10-01 12:41:12 -06:00
commit 5139653429
11 changed files with 319 additions and 0 deletions

49
init.c Normal file
View 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;
}