aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-11-02 15:25:28 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-11-02 15:25:28 +0100
commitf5e8b4278822f2413bf7e47466f55cc1a0fcca9a (patch)
tree831d2e2e32d4ede4dcb06be749d475ed72b868a3
parent9c143ce52da11ec3d21a3491c3749841d3dc10f0 (diff)
downloadbusybox-w32-f5e8b4278822f2413bf7e47466f55cc1a0fcca9a.tar.gz
busybox-w32-f5e8b4278822f2413bf7e47466f55cc1a0fcca9a.tar.bz2
busybox-w32-f5e8b4278822f2413bf7e47466f55cc1a0fcca9a.zip
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>
-rw-r--r--init/init.c31
1 files changed, 8 insertions, 23 deletions
diff --git a/init/init.c b/init/init.c
index 5304e5c2c..6f3374eac 100644
--- a/init/init.c
+++ b/init/init.c
@@ -1064,6 +1064,12 @@ int init_main(int argc UNUSED_PARAM, char **argv)
1064#endif 1064#endif
1065 1065
1066 if (!DEBUG_INIT) { 1066 if (!DEBUG_INIT) {
1067 /* Some users send poweroff signals to init VERY early.
1068 * To handle this, mask signals early,
1069 * and unmask them only after signal handlers are installed.
1070 */
1071 sigprocmask_allsigs(SIG_BLOCK);
1072
1067 /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */ 1073 /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
1068 if (getpid() != 1 1074 if (getpid() != 1
1069 && (!ENABLE_LINUXRC || applet_name[0] != 'l') /* not linuxrc? */ 1075 && (!ENABLE_LINUXRC || applet_name[0] != 'l') /* not linuxrc? */
@@ -1106,29 +1112,6 @@ int init_main(int argc UNUSED_PARAM, char **argv)
1106 message(L_CONSOLE | L_LOG, "init started: %s", bb_banner); 1112 message(L_CONSOLE | L_LOG, "init started: %s", bb_banner);
1107#endif 1113#endif
1108 1114
1109#if 0
1110/* It's 2013, does anyone really still depend on this? */
1111/* If you do, consider adding swapon to sysinit actions then! */
1112/* struct sysinfo is linux-specific */
1113# ifdef __linux__
1114 /* Make sure there is enough memory to do something useful. */
1115 /*if (ENABLE_SWAPONOFF) - WRONG: we may have non-bbox swapon*/ {
1116 struct sysinfo info;
1117
1118 if (sysinfo(&info) == 0
1119 && (info.mem_unit ? info.mem_unit : 1) * (long long)info.totalram < 1024*1024
1120 ) {
1121 message(L_CONSOLE, "Low memory, forcing swapon");
1122 /* swapon -a requires /proc typically */
1123 new_init_action(SYSINIT, "mount -t proc proc /proc", "");
1124 /* Try to turn on swap */
1125 new_init_action(SYSINIT, "swapon -a", "");
1126 run_actions(SYSINIT); /* wait and removing */
1127 }
1128 }
1129# endif
1130#endif
1131
1132 /* Check if we are supposed to be in single user mode */ 1115 /* Check if we are supposed to be in single user mode */
1133 if (argv[1] 1116 if (argv[1]
1134 && (strcmp(argv[1], "single") == 0 || strcmp(argv[1], "-s") == 0 || LONE_CHAR(argv[1], '1')) 1117 && (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)
1204 + (1 << SIGHUP) /* reread /etc/inittab */ 1187 + (1 << SIGHUP) /* reread /etc/inittab */
1205#endif 1188#endif
1206 , record_signo); 1189 , record_signo);
1190
1191 sigprocmask_allsigs(SIG_UNBLOCK);
1207 } 1192 }
1208 1193
1209 /* Now run everything that needs to be run */ 1194 /* Now run everything that needs to be run */