From: Yu Watanabe Date: Wed, 9 Oct 2024 00:42:52 +0000 (+0900) Subject: login: allow to cancel delayed action by CancelScheduledShutdown() X-Git-Tag: v257-rc1~269^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dc09c61f19dbf5399bf47a43b02fabd790bda37d;p=thirdparty%2Fsystemd.git login: allow to cancel delayed action by CancelScheduledShutdown() Fixes #34554. --- diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 6dd375c1646..ee449a8445d 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1980,6 +1980,21 @@ static int delay_shutdown_or_sleep( return 0; } +static void cancel_delayed_action(Manager *m) { + assert(m); + + (void) sd_event_source_set_enabled(m->inhibit_timeout_source, SD_EVENT_OFF); + + /* When m->action_job is NULL, the delayed action has not been triggered yet. Let's clear it to + * accept later shutdown and friends. + * + * When m->action_job is non-NULL, the delayed action has been already triggered, and now we are + * waiting for the job being finished. In match_job_removed(), the triggered action will be used. + * Hence, do not clear it. */ + if (!m->action_job) + m->delayed_action = NULL; +} + int bus_manager_shutdown_or_sleep_now_or_later( Manager *m, const HandleActionData *a, @@ -2722,6 +2737,7 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd username, tty, logind_wall_tty_filter, m); } + cancel_delayed_action(m); reset_scheduled_shutdown(m); return sd_bus_reply_method_return(message, "b", true);