From 24299ab5d9f94221db2438d723b6f359f2ada9c1 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Wed, 21 Mar 2018 08:44:14 +0100 Subject: [PATCH] Fix #105: Only remove /etc/nologin when moving from runlevel 0, 1, 6 Signed-off-by: Joachim Nilsson --- src/sm.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/sm.c b/src/sm.c index 932b6ec0..c67a9276 100644 --- a/src/sm.c +++ b/src/sm.c @@ -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())