Merge pull request #30927 from YHNdnzj/logind-action-job

logind-dbus: refuse multiple jobs in method_do_shutdown_or_sleep too
This commit is contained in:
Luca Boccassi
2024-01-14 12:56:42 +00:00
committed by GitHub
+14 -4
View File
@@ -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;
@@ -2125,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);
@@ -2401,8 +2410,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;
}