}
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);
if (n >= c->elapse)
return;
- if (c->wall_message[0])
- utmp_wall(c->wall_message);
+ 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);
- free(l);
- }
+ utmp_wall(l, NULL);
+ free(l);
}
}
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;
if ((pollfd[i].fd = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK|TFD_CLOEXEC)) < 0) {
log_error("timerfd_create(): %m");
- failed = false;
+ failed = true;
}
}
if (pollfd[FD_NOLOGIN_TIMER].revents) {
int e;
- log_info("Creating /etc/nologin, blocking further logins...");
+ log_info("Creating /run/nologin, blocking further logins...");
- if ((e = touch("/etc/nologin")) < 0)
- log_error("Failed to create /etc/nologin: %s", strerror(-e));
+ if ((e = write_one_line_file_atomic("/run/nologin", "System is going down.")) < 0)
+ log_error("Failed to create /run/nologin: %s", strerror(-e));
else
unlink_nologin = true;
close_nointr_nofail(pollfd[i].fd);
if (unlink_nologin)
- unlink("/etc/nologin");
+ unlink("/run/nologin");
- if (exec_shutdown) {
+ if (exec_shutdown && !c.dry_run) {
char sw[3];
sw[0] = '-';