return 1;
}
-static void warn_wall(struct shutdownd_command *c) {
+static void warn_wall(usec_t n, struct shutdownd_command *c) {
assert(c);
assert(c->warn_wall);
+ if (n >= c->elapse)
+ return;
+
if (c->wall_message[0])
utmp_wall(c->wall_message);
else {
char date[FORMAT_TIMESTAMP_MAX];
const char* prefix;
- char *l;
+ char *l = NULL;
if (c->mode == 'H')
- prefix = "The system is going down for system halt at";
+ 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";
+ prefix = "The system is going down for power-off at ";
else if (c->mode == 'r')
- prefix = "The system is going down for reboot at";
+ 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)
+ 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);
left = elapse - n;
for (i = 0; i < ELEMENTSOF(table); i++)
- if (n + table[i].delay >= elapse)
+ if (n + table[i].delay >= elapse) {
sub = ((left / table[i].interval) * table[i].interval);
+ break;
+ }
if (i >= ELEMENTSOF(table))
sub = ((left / USEC_PER_HOUR) * USEC_PER_HOUR);
/* Warn immediately if less than 15 minutes are left */
if (n < c.elapse &&
n + 15*USEC_PER_MINUTE >= c.elapse)
- warn_wall(&c);
+ warn_wall(n, &c);
}
/* Disallow logins 5 minutes prior to shutdown */
if (pollfd[FD_WALL_TIMER].revents) {
struct itimerspec its;
- warn_wall(&c);
+ warn_wall(n, &c);
flush_fd(pollfd[FD_WALL_TIMER].fd);
/* Restart timer */
if (pollfd[FD_NOLOGIN_TIMER].revents) {
int e;
+ log_info("Creating /etc/nologin, blocking further logins...");
+
if ((e = touch("/etc/nologin")) < 0)
log_error("Failed to create /etc/nologin: %s", strerror(-e));
else
sw[1] = c.mode;
sw[2] = 0;
- execl(SYSTEMCTL_BINARY_PATH, "shutdown", sw, "now", NULL);
+ execl(SYSTEMCTL_BINARY_PATH,
+ "shutdown",
+ sw,
+ "now",
+ (c.warn_wall && c.wall_message[0]) ? c.wall_message :
+ (c.warn_wall ? NULL : "--no-wall"),
+ NULL);
+
log_error("Failed to execute /sbin/shutdown: %m");
}
static int shutdown_help(void) {
- printf("%s [OPTIONS...] [now] [WALL...]\n\n"
+ printf("%s [OPTIONS...] [TIME] [WALL...]\n\n"
"Shut down the system.\n\n"
" --help Show this help\n"
" -H --halt Halt the machine\n"
return -EINVAL;
n = now(CLOCK_REALTIME);
- s = (time_t) n / USEC_PER_SEC;
+ s = (time_t) (n / USEC_PER_SEC);
+
+ zero(tm);
assert_se(localtime_r(&s, &tm));
tm.tm_hour = (int) hour;
tm.tm_min = (int) minute;
+ tm.tm_sec = 0;
assert_se(s = mktime(&tm));
return r;
}
} else
- arg_when = USEC_PER_MINUTE;
+ arg_when = now(CLOCK_REALTIME) + USEC_PER_MINUTE;
/* We skip the time argument */
if (argc > optind + 1)
if (arg_when > 0) {
char *m;
+ char date[FORMAT_TIMESTAMP_MAX];
m = strv_join(arg_wall, " ");
r = send_shutdownd(arg_when,
if (r < 0)
log_warning("Failed to talk to shutdownd, proceeding with immediate shutdown: %s", strerror(-r));
- else
+ else {
+ log_info("Shutdown scheduled for %s, use 'shutdown -c' to cancel.",
+ format_timestamp(date, sizeof(date), arg_when));
return 0;
+ }
}
if (!arg_dry && !arg_immediate)