Fix #105: Only remove /etc/nologin when moving from runlevel 0, 1, 6

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2018-03-21 08:44:14 +01:00
1 parent 90249e50ef
commit 24299ab5d9
1 file changed
+17 -4
+17 -4
View File
@@ -72,6 +72,22 @@ static char *sm_status(sm_state_t state)
}
}
/*
* Disable login in single user mode and shutdown/reboot
*
* Re-enable only when going from these runlevels, this way a user can
* manage /etc/nologin manually within the other runlevels without us
* pulling the rug from under their feet.
*/
static void nologin(void)
{
if (runlevel == 1 || runlevel == 0 || runlevel == 6)
touch("/etc/nologin");
if (prevlevel == 1 || prevlevel == 0 || prevlevel == 6)
erase("/etc/nologin");
}
void sm_set_runlevel(sm_t *sm, int newlevel)
{
sm->newlevel = newlevel;
@@ -137,10 +153,7 @@ restart:
runlevel_set(prevlevel, runlevel);
/* Disable login in single-user mode as well as shutdown/reboot */
if (runlevel == 1 || runlevel == 0 || runlevel == 6)
touch("/etc/nologin");
else
erase("/etc/nologin");
nologin();
/* Make sure to (re)load all *.conf in /etc/finit.d/ */
if (conf_any_change())