fixed init
This commit is contained in:
parent
a5080fbb48
commit
9563cf2009
4
config.h
4
config.h
|
@ -31,8 +31,8 @@
|
|||
|
||||
/* Init scripts */
|
||||
#ifdef INIT
|
||||
char *INIT_POWEROFF[] = {"/etc/rc.poweroff"};
|
||||
char *INIT_START[] = {"/etc/rc.init"};
|
||||
char *INIT_POWEROFF[] = {"/etc/rc.poweroff", NULL};
|
||||
char *INIT_START[] = {"/etc/rc.init", NULL};
|
||||
#define INIT_MSG "Starting micro-init..."
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#!/bin/sh
|
||||
echo "Closing processes..."
|
||||
kill -a -s TERM
|
||||
sleep 5
|
||||
|
||||
echo "Umounting..."
|
||||
umount /proc
|
||||
umount /sys
|
||||
umount /dev
|
||||
umount /tmp
|
||||
|
||||
echo "Closing processes..."
|
||||
kill -a -s TERM
|
||||
sleep 5
|
||||
|
||||
echo "Poweroff..."
|
||||
|
|
|
@ -11,31 +11,24 @@
|
|||
|
||||
void poweroff(int sig) {
|
||||
printf("Syncing...\n");
|
||||
|
||||
sync();
|
||||
sleep(5);
|
||||
|
||||
if (sig == SIGUSR1)
|
||||
reboot(RB_POWER_OFF);
|
||||
|
||||
else if (sig == SIGKILL)
|
||||
else if (sig == SIGUSR2)
|
||||
reboot(RB_AUTOBOOT);
|
||||
}
|
||||
|
||||
void execute(char *argv[], sigset_t *set) {
|
||||
void execute(char *argv[]) {
|
||||
pid_t pid;
|
||||
if ((pid = fork()) == 0) {
|
||||
sigprocmask(SIG_UNBLOCK, set, NULL);
|
||||
setsid();
|
||||
execvp(argv[0], argv);
|
||||
|
||||
fprintf(stderr, "init: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int status = 0;
|
||||
waitpid(pid, &status, 0);
|
||||
|
||||
if (status != 0) {
|
||||
fprintf(stderr, "init: Init script returned %d\nRebooting...\n", status);
|
||||
fprintf(stderr, "init: Failed to run %s\nRebooting...\n", argv[0]);
|
||||
poweroff(SIGKILL);
|
||||
}
|
||||
}
|
||||
|
@ -49,17 +42,21 @@ int main(void) {
|
|||
chdir("/");
|
||||
printf("%s\n", INIT_MSG);
|
||||
|
||||
/* Start main service */
|
||||
sigset_t set;
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGUSR2);
|
||||
sigaddset(&set, SIGUSR1);
|
||||
|
||||
/* Start main service */
|
||||
sigprocmask(SIG_BLOCK, &set, NULL);
|
||||
execute(INIT_START, &set);
|
||||
execute(INIT_START);
|
||||
|
||||
/* Sig handler */
|
||||
int sig = 0;
|
||||
while (1) {
|
||||
if (sigwait(&set, &sig) == 0)
|
||||
if (sig == SIGKILL || sig == SIGUSR1) {
|
||||
execute(INIT_POWEROFF, &set);
|
||||
if (sig == SIGUSR2 || sig == SIGUSR1) {
|
||||
execute(INIT_POWEROFF);
|
||||
poweroff(sig);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#!/bin/sh
|
||||
kill -s KILL 1
|
||||
kill -s USR2 1
|
||||
|
|
Loading…
Reference in New Issue