Skip to content

Commit

Permalink
logind: fix wall message for immediate shutdowns
Browse files Browse the repository at this point in the history
An elapse time of zero means NOW which should trigger a wall
message.
  • Loading branch information
lnussel committed Jan 25, 2022
1 parent 0600669 commit 90b1ec0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
46 changes: 29 additions & 17 deletions src/login/logind-dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,29 @@ static int verify_shutdown_creds(
return 0;
}

static int setup_wall_message_timer(Manager *m, sd_bus_message* message) {
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
int r;

r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_AUGMENT|SD_BUS_CREDS_TTY|SD_BUS_CREDS_UID, &creds);
if (r >= 0) {
const char *tty = NULL;

(void) sd_bus_creds_get_uid(creds, &m->scheduled_shutdown_uid);
(void) sd_bus_creds_get_tty(creds, &tty);

r = free_and_strdup(&m->scheduled_shutdown_tty, tty);
if (r < 0)
return log_oom();
}

r = manager_setup_wall_message_timer(m);
if (r < 0)
return r;

return 0;
}

static int method_do_shutdown_or_sleep(
Manager *m,
sd_bus_message *message,
Expand Down Expand Up @@ -1922,6 +1945,8 @@ static int method_do_shutdown_or_sleep(
if (r != 0)
return r;

(void) setup_wall_message_timer(m, message);

r = bus_manager_shutdown_or_sleep_now_or_later(m, unit_name, w, error);
if (r < 0)
return r;
Expand Down Expand Up @@ -2189,7 +2214,6 @@ static int manager_scheduled_shutdown_handler(

static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
const char *action_multiple_sessions = NULL;
const char *action_ignore_inhibit = NULL;
const char *action = NULL;
Expand Down Expand Up @@ -2270,23 +2294,11 @@ static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_

m->scheduled_shutdown_timeout = elapse;

r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_AUGMENT|SD_BUS_CREDS_TTY|SD_BUS_CREDS_UID, &creds);
if (r >= 0) {
const char *tty = NULL;

(void) sd_bus_creds_get_uid(creds, &m->scheduled_shutdown_uid);
(void) sd_bus_creds_get_tty(creds, &tty);

r = free_and_strdup(&m->scheduled_shutdown_tty, tty);
if (r < 0) {
m->scheduled_shutdown_timeout_source = sd_event_source_unref(m->scheduled_shutdown_timeout_source);
return log_oom();
}
}

r = manager_setup_wall_message_timer(m);
if (r < 0)
r = setup_wall_message_timer(m, message);
if (r < 0) {
m->scheduled_shutdown_timeout_source = sd_event_source_unref(m->scheduled_shutdown_timeout_source);
return r;
}

r = update_schedule_file(m);
if (r < 0)
Expand Down
4 changes: 2 additions & 2 deletions src/login/logind-utmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ int manager_setup_wall_message_timer(Manager *m) {
return 0;
}

if (elapse < n)
if (elapse > 0 && elapse < n)
return 0;

/* Warn immediately if less than 15 minutes are left */
if (elapse - n < 15 * USEC_PER_MINUTE) {
if (elapse == 0 || elapse - n < 15 * USEC_PER_MINUTE) {
r = warn_wall(m, n);
if (r == 0)
return 0;
Expand Down

0 comments on commit 90b1ec0

Please sign in to comment.