From 1f4cb8c9cf0459ebd34b95eaf71b691f30d903b8 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sun, 14 Jan 2024 05:14:25 +0800 Subject: [PATCH 1/2] logind-dbus: minor modernization --- src/login/logind-dbus.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 99b9da6ba1..2b993fd842 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1748,6 +1748,7 @@ static int execute_shutdown_or_sleep( int r; assert(m); + assert(!m->action_job); assert(a); if (a->inhibit_what == INHIBIT_SHUTDOWN) @@ -1767,9 +1768,11 @@ static int execute_shutdown_or_sleep( if (r < 0) goto error; - r = free_and_strdup(&m->action_job, p); - if (r < 0) + m->action_job = strdup(p); + if (!m->action_job) { + r = -ENOMEM; goto error; + } m->delayed_action = a; @@ -2401,8 +2404,9 @@ static int manager_scheduled_shutdown_handler( /* Don't allow multiple jobs being executed at the same time */ if (m->delayed_action) { - r = -EALREADY; - log_error("Scheduled shutdown to %s failed: shutdown or sleep operation already in progress", a->target); + r = log_error_errno(SYNTHETIC_ERRNO(EALREADY), + "Scheduled shutdown to %s failed: shutdown or sleep operation already in progress.", + a->target); goto error; } From 3eb8acda96eb99d45eef42fa8c5d035180d0b25a Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sun, 14 Jan 2024 05:14:42 +0800 Subject: [PATCH 2/2] logind-dbus: refuse multiple jobs in method_do_shutdown_or_sleep too Fixes #30917 --- src/login/logind-dbus.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 2b993fd842..932eb42b4e 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -2128,6 +2128,12 @@ static int method_do_shutdown_or_sleep( if (r != 0) return r; + if (m->delayed_action) + return sd_bus_error_setf(error, BUS_ERROR_OPERATION_IN_PROGRESS, + "Action %s already in progress, refusing requested %s operation.", + handle_action_to_string(m->delayed_action->handle), + handle_action_to_string(a->handle)); + /* reset case we're shorting a scheduled shutdown */ m->unlink_nologin = false; reset_scheduled_shutdown(m);