X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshutdownd%2Fshutdownd.c;h=119385d67fb3c586baaf9cbc88aaf2410e124ac5;hb=80cfe9e163b1c92f917e0a5e053b148fca790677;hp=6eb8ed9bf8ee2af14d91c25613f0cd3bf88acd79;hpb=d2e54fae5ca7a0f71b5ac8b356a589ff0a09ea0a;p=elogind.git diff --git a/src/shutdownd/shutdownd.c b/src/shutdownd/shutdownd.c index 6eb8ed9bf..119385d67 100644 --- a/src/shutdownd/shutdownd.c +++ b/src/shutdownd/shutdownd.c @@ -38,6 +38,7 @@ #include "util.h" #include "utmp-wtmp.h" #include "mkdir.h" +#include "fileio.h" union shutdown_buffer { struct sd_shutdown_command command; @@ -136,6 +137,8 @@ static void warn_wall(usec_t n, struct sd_shutdown_command *c) { prefix = "The system is going down for reboot at "; else if (c->mode == SD_SHUTDOWN_KEXEC) prefix = "The system is going down for kexec reboot at "; + else if (c->mode == SD_SHUTDOWN_NONE) + prefix = "The system shutdown has been cancelled at "; else assert_not_reached("Unknown mode!"); @@ -154,29 +157,26 @@ static usec_t when_wall(usec_t n, usec_t elapse) { usec_t delay; usec_t interval; } table[] = { - { 10 * USEC_PER_MINUTE, USEC_PER_MINUTE }, - { USEC_PER_HOUR, 15 * USEC_PER_MINUTE }, - { 3 * USEC_PER_HOUR, 30 * USEC_PER_MINUTE } + { 0, USEC_PER_MINUTE }, + { 10 * USEC_PER_MINUTE, 15 * USEC_PER_MINUTE }, + { USEC_PER_HOUR, 30 * USEC_PER_MINUTE }, + { 3 * USEC_PER_HOUR, USEC_PER_HOUR }, }; usec_t left, sub; - unsigned i; + unsigned i = ELEMENTSOF(table) - 1; /* If the time is already passed, then don't announce */ if (n >= elapse) return 0; left = elapse - n; - for (i = 0; i < ELEMENTSOF(table); i++) - if (n + table[i].delay >= elapse) { - sub = ((left / table[i].interval) * table[i].interval); - break; - } + while (left < table[i].delay) + i--; + sub = (left / table[i].interval) * table[i].interval; - if (i >= ELEMENTSOF(table)) - sub = ((left / USEC_PER_HOUR) * USEC_PER_HOUR); - - return elapse > sub ? elapse - sub : 1; + assert(sub < elapse); + return elapse - sub; } static usec_t when_nologin(usec_t elapse) { @@ -212,10 +212,8 @@ static int update_schedule_file(struct sd_shutdown_command *c) { } t = cescape(c->wall_message); - if (!t) { - log_error("Out of memory"); - return -ENOMEM; - } + if (!t) + return log_oom(); r = fopen_temporary("/run/systemd/shutdown/scheduled", &f, &temp_path); if (r < 0) { @@ -356,6 +354,8 @@ int main(int argc, char *argv[]) { if (!scheduled(&b.command)) { log_info("Shutdown canceled."); + if (b.command.warn_wall) + warn_wall(0, &b.command); break; }