]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
login: allow to cancel delayed action by CancelScheduledShutdown()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 9 Oct 2024 00:42:52 +0000 (09:42 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 9 Oct 2024 16:43:21 +0000 (01:43 +0900)
Fixes #34554.

src/login/logind-dbus.c

index 6dd375c1646a455bb0a4042ff8867cb0a75bc116..ee449a8445d3a98bb34f1dc702a0ab63af358638 100644 (file)
@@ -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);