X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshutdownd.c;h=0ffa8b28815f4c1805b14e16c77cc7853609f272;hb=4d8a7798e7f12c6400495cbc4d0ad57ed20ce90a;hp=13819417c3f5da1047aad14c5b9c129a909b894c;hpb=34ca941cec76bbfdfd02c705b76bc1b53ea2bcd1;p=elogind.git diff --git a/src/shutdownd.c b/src/shutdownd.c index 13819417c..0ffa8b288 100644 --- a/src/shutdownd.c +++ b/src/shutdownd.c @@ -100,6 +100,9 @@ static int read_packet(int fd, struct shutdownd_command *_c) { } static void warn_wall(usec_t n, struct shutdownd_command *c) { + char date[FORMAT_TIMESTAMP_MAX]; + const char *prefix; + char *l = NULL; assert(c); assert(c->warn_wall); @@ -107,28 +110,21 @@ static void warn_wall(usec_t n, struct shutdownd_command *c) { if (n >= c->elapse) return; - if (c->wall_message[0]) - utmp_wall(c->wall_message, NULL); + if (c->mode == 'H') + prefix = "The system is going down for system halt at "; + else if (c->mode == 'P') + prefix = "The system is going down for power-off at "; + else if (c->mode == 'r') + prefix = "The system is going down for reboot at "; + else + assert_not_reached("Unknown mode!"); + + if (asprintf(&l, "%s%s%s%s!", c->wall_message, c->wall_message[0] ? "\n" : "", + prefix, format_timestamp(date, sizeof(date), c->elapse)) < 0) + log_error("Failed to allocate wall message"); else { - char date[FORMAT_TIMESTAMP_MAX]; - const char* prefix; - char *l = NULL; - - if (c->mode == 'H') - prefix = "The system is going down for system halt at "; - else if (c->mode == 'P') - prefix = "The system is going down for power-off at "; - else if (c->mode == 'r') - prefix = "The system is going down for reboot at "; - else - assert_not_reached("Unknown mode!"); - - if (asprintf(&l, "%s%s!", prefix, format_timestamp(date, sizeof(date), c->elapse)) < 0) - log_error("Failed to allocate wall message"); - else { - utmp_wall(l, NULL); - free(l); - } + utmp_wall(l, NULL); + free(l); } } @@ -197,6 +193,8 @@ int main(int argc, char *argv[]) { log_parse_environment(); log_open(); + umask(0022); + if ((n_fds = sd_listen_fds(true)) < 0) { log_error("Failed to read listening file descriptors from environment: %s", strerror(-r)); return EXIT_FAILURE; @@ -348,7 +346,7 @@ finish: if (unlink_nologin) unlink("/run/nologin"); - if (exec_shutdown) { + if (exec_shutdown && !c.dry_run) { char sw[3]; sw[0] = '-';