2 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version 2.1
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include <sys/types.h>
18 #include <sys/reboot.h>
20 #include <libubox/uloop.h>
32 #include "../utils/utils.h"
34 #include "../watchdog.h"
36 unsigned int debug
= 0;
39 signal_shutdown(int signal
, siginfo_t
*siginfo
, void *data
)
41 fprintf(stderr
, "reboot\n");
50 static struct sigaction sa_shutdown
= {
51 .sa_sigaction
= signal_shutdown
,
52 .sa_flags
= SA_SIGINFO
62 res
= get_cmdline_val("init_debug", line
, sizeof(line
));
64 r
= strtol(line
, NULL
, 10);
65 if ((r
!= LONG_MIN
) && (r
!= LONG_MAX
))
71 main(int argc
, char **argv
)
75 ulog_open(ULOG_KMSG
, LOG_DAEMON
, "init");
77 sigaction(SIGTERM
, &sa_shutdown
, NULL
);
78 sigaction(SIGUSR1
, &sa_shutdown
, NULL
);
79 sigaction(SIGUSR2
, &sa_shutdown
, NULL
);
87 char *kmod
[] = { "/sbin/kmodloader", "/etc/modules-boot.d/", NULL
};
90 int fd
= open("/dev/null", O_RDWR
);
93 dup2(fd
, STDIN_FILENO
);
94 dup2(fd
, STDOUT_FILENO
);
95 dup2(fd
, STDERR_FILENO
);
96 if (fd
> STDERR_FILENO
)
100 execvp(kmod
[0], kmod
);
101 ERROR("Failed to start kmodloader\n");
105 ERROR("Failed to start kmodloader instance\n");
109 for (i
= 0; i
< 120; i
++) {
110 if (waitpid(pid
, NULL
, WNOHANG
) > 0)