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 #if defined(WITH_SELINUX)
33 #include <selinux/selinux.h>
36 #include "../utils/utils.h"
38 #include "../watchdog.h"
40 unsigned int debug
= 0;
43 signal_shutdown(int signal
, siginfo_t
*siginfo
, void *data
)
45 fprintf(stderr
, "reboot\n");
54 static struct sigaction sa_shutdown
= {
55 .sa_sigaction
= signal_shutdown
,
56 .sa_flags
= SA_SIGINFO
66 res
= get_cmdline_val("init_debug", line
, sizeof(line
));
68 r
= strtol(line
, NULL
, 10);
69 if ((r
!= LONG_MIN
) && (r
!= LONG_MAX
))
74 #if defined(WITH_SELINUX)
81 /* SELinux already initialized */
82 if (getenv("SELINUX_INIT"))
85 putenv("SELINUX_INIT=1");
87 ret
= selinux_init_load_policy(&enforce
);
92 fprintf(stderr
, "Cannot load SELinux policy, but system in enforcing mode. Halting.\n");
107 main(int argc
, char **argv
)
111 ulog_open(ULOG_KMSG
, LOG_DAEMON
, "init");
113 sigaction(SIGTERM
, &sa_shutdown
, NULL
);
114 sigaction(SIGUSR1
, &sa_shutdown
, NULL
);
115 sigaction(SIGUSR2
, &sa_shutdown
, NULL
);
116 sigaction(SIGPWR
, &sa_shutdown
, NULL
);
126 char *kmod
[] = { "/sbin/kmodloader", "/etc/modules-boot.d/", NULL
};
129 patch_stdio("/dev/null");
131 execvp(kmod
[0], kmod
);
132 ERROR("Failed to start kmodloader: %m\n");
136 ERROR("Failed to start kmodloader instance: %m\n");
138 const struct timespec req
= {0, 10 * 1000 * 1000};
141 for (i
= 0; i
< 1200; i
++) {
142 if (waitpid(pid
, NULL
, WNOHANG
) > 0)
144 nanosleep(&req
, NULL
);