init: reduce the window when init can lose reboot/poweroff signals

function                                             old     new   delta
init_main                                            695     712     +17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2017-11-02 15:25:28 +01:00
parent 9c143ce52d
commit f5e8b42788

View File

@ -1064,6 +1064,12 @@ int init_main(int argc UNUSED_PARAM, char **argv)
#endif #endif
if (!DEBUG_INIT) { if (!DEBUG_INIT) {
/* Some users send poweroff signals to init VERY early.
* To handle this, mask signals early,
* and unmask them only after signal handlers are installed.
*/
sigprocmask_allsigs(SIG_BLOCK);
/* Expect to be invoked as init with PID=1 or be invoked as linuxrc */ /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
if (getpid() != 1 if (getpid() != 1
&& (!ENABLE_LINUXRC || applet_name[0] != 'l') /* not linuxrc? */ && (!ENABLE_LINUXRC || applet_name[0] != 'l') /* not linuxrc? */
@ -1106,29 +1112,6 @@ int init_main(int argc UNUSED_PARAM, char **argv)
message(L_CONSOLE | L_LOG, "init started: %s", bb_banner); message(L_CONSOLE | L_LOG, "init started: %s", bb_banner);
#endif #endif
#if 0
/* It's 2013, does anyone really still depend on this? */
/* If you do, consider adding swapon to sysinit actions then! */
/* struct sysinfo is linux-specific */
# ifdef __linux__
/* Make sure there is enough memory to do something useful. */
/*if (ENABLE_SWAPONOFF) - WRONG: we may have non-bbox swapon*/ {
struct sysinfo info;
if (sysinfo(&info) == 0
&& (info.mem_unit ? info.mem_unit : 1) * (long long)info.totalram < 1024*1024
) {
message(L_CONSOLE, "Low memory, forcing swapon");
/* swapon -a requires /proc typically */
new_init_action(SYSINIT, "mount -t proc proc /proc", "");
/* Try to turn on swap */
new_init_action(SYSINIT, "swapon -a", "");
run_actions(SYSINIT); /* wait and removing */
}
}
# endif
#endif
/* Check if we are supposed to be in single user mode */ /* Check if we are supposed to be in single user mode */
if (argv[1] if (argv[1]
&& (strcmp(argv[1], "single") == 0 || strcmp(argv[1], "-s") == 0 || LONE_CHAR(argv[1], '1')) && (strcmp(argv[1], "single") == 0 || strcmp(argv[1], "-s") == 0 || LONE_CHAR(argv[1], '1'))
@ -1204,6 +1187,8 @@ int init_main(int argc UNUSED_PARAM, char **argv)
+ (1 << SIGHUP) /* reread /etc/inittab */ + (1 << SIGHUP) /* reread /etc/inittab */
#endif #endif
, record_signo); , record_signo);
sigprocmask_allsigs(SIG_UNBLOCK);
} }
/* Now run everything that needs to be run */ /* Now run everything that needs to be run */