mirror of
https://github.com/troglobit/finit.git
synced 2026-11-17 19:30:29 +00:00
shutdown: add time argument, wall message, and cancel
shutdown ignored everything after its options, so a delayed shutdown
went down right away:
shutdown -r +10 "Upgrading, back in five"
Take a time, now, +MIN, or the next HH:MM, and an optional message.
Finit keeps the countdown, so it survives logging out:
- warns logged-in users at 60, 30, 15 and 10 minutes left, then
every minute from five, and on the console
- writes the message to /etc/nologin from five minutes before,
leaving one already in place alone
- shutdown -c cancels, and a new shutdown TIME replaces it
Without a time, or with now and no message, shutdown acts right away
as before. An immediate reboot, halt, or power-off, also over D-Bus,
cancels a scheduled one. The warnings are written by a child, reading
utmp and closing a serial tty can block.
Fixes #149
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
12 files changed
+542
-53
No files matched your search
@@ -48,6 +48,7 @@
|
||||
#include "schedule.h"
|
||||
#include "service.h"
|
||||
#include "sm.h"
|
||||
#include "shutdown.h"
|
||||
#include "sig.h"
|
||||
#include "util.h"
|
||||
|
||||
@@ -241,43 +242,9 @@ static int do_reboot(int cmd, int timeout, char *buf, size_t len)
|
||||
|
||||
switch (cmd) {
|
||||
case INIT_CMD_REBOOT:
|
||||
halt = SHUT_REBOOT;
|
||||
break;
|
||||
|
||||
case INIT_CMD_HALT:
|
||||
halt = SHUT_HALT;
|
||||
break;
|
||||
|
||||
case INIT_CMD_POWEROFF:
|
||||
halt = SHUT_OFF;
|
||||
break;
|
||||
|
||||
case INIT_CMD_SUSPEND:
|
||||
break;
|
||||
|
||||
default:
|
||||
return 255;
|
||||
}
|
||||
|
||||
shutdown_bypass(timeout);
|
||||
|
||||
switch (cmd) {
|
||||
case INIT_CMD_REBOOT:
|
||||
dbg("reboot");
|
||||
halt = SHUT_REBOOT;
|
||||
sm_runlevel(6);
|
||||
break;
|
||||
|
||||
case INIT_CMD_HALT:
|
||||
dbg("halt");
|
||||
halt = SHUT_HALT;
|
||||
sm_runlevel(0);
|
||||
break;
|
||||
|
||||
case INIT_CMD_POWEROFF:
|
||||
dbg("poweroff");
|
||||
halt = SHUT_OFF;
|
||||
sm_runlevel(0);
|
||||
shutdown_now(cmd, timeout);
|
||||
break;
|
||||
|
||||
case INIT_CMD_SUSPEND:
|
||||
@@ -293,8 +260,7 @@ static int do_reboot(int cmd, int timeout, char *buf, size_t len)
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Handled previously */
|
||||
break;
|
||||
return 255;
|
||||
}
|
||||
|
||||
return rc;
|
||||
@@ -384,6 +350,7 @@ static void api_cb(uev_t *w, void *arg, int events)
|
||||
case INIT_CMD_HALT:
|
||||
case INIT_CMD_POWEROFF:
|
||||
case INIT_CMD_SUSPEND:
|
||||
case INIT_CMD_SHUTDOWN:
|
||||
if (IS_RESERVED_RUNLEVEL(runlevel)) {
|
||||
strterm(rq.data, sizeof(rq.data));
|
||||
warnx("Unsupported command (cmd: %d, data: %s) in runlevel S and 6/0.",
|
||||
@@ -484,6 +451,17 @@ static void api_cb(uev_t *w, void *arg, int events)
|
||||
result = do_reboot(rq.cmd, rq.sleeptime, rq.data, sizeof(rq.data));
|
||||
break;
|
||||
|
||||
case INIT_CMD_SHUTDOWN:
|
||||
strterm(rq.data, sizeof(rq.data));
|
||||
result = shutdown_schedule(rq.runlevel, rq.sleeptime, rq.data);
|
||||
break;
|
||||
|
||||
case INIT_CMD_SHUTDOWN_CANCEL:
|
||||
result = shutdown_cancel();
|
||||
if (result)
|
||||
strlcpy(rq.data, "No scheduled shutdown to cancel.", sizeof(rq.data));
|
||||
break;
|
||||
|
||||
case INIT_CMD_SWITCH_ROOT:
|
||||
result = do_switch_root_api(sd, &rq);
|
||||
if (result)
|
||||
|
||||
Reference in new issue
Block a user