logind-action: also check .target unit state when selecting sleep action
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "bus-error.h"
|
||||
#include "bus-unit-util.h"
|
||||
#include "bus-util.h"
|
||||
#include "conf-parser.h"
|
||||
#include "format-util.h"
|
||||
@@ -166,15 +167,24 @@ int handle_action_get_enabled_sleep_actions(HandleActionSleepMask mask, char ***
|
||||
return 0;
|
||||
}
|
||||
|
||||
HandleAction handle_action_sleep_select(HandleActionSleepMask mask) {
|
||||
HandleAction handle_action_sleep_select(Manager *m) {
|
||||
assert(m);
|
||||
|
||||
FOREACH_ARRAY(i, sleep_actions, ELEMENTSOF(sleep_actions)) {
|
||||
HandleActionSleepMask a = 1U << *i;
|
||||
HandleActionSleepMask action_mask = 1U << *i;
|
||||
const HandleActionData *a;
|
||||
_cleanup_free_ char *load_state = NULL;
|
||||
|
||||
if (!FLAGS_SET(mask, a))
|
||||
if (!FLAGS_SET(m->handle_action_sleep_mask, action_mask))
|
||||
continue;
|
||||
|
||||
if (handle_action_sleep_supported(*i))
|
||||
a = ASSERT_PTR(handle_action_lookup(*i));
|
||||
|
||||
if (sleep_supported(a->sleep_operation) <= 0)
|
||||
continue;
|
||||
|
||||
(void) unit_load_state(m->bus, a->target, &load_state);
|
||||
if (streq_ptr(load_state, "loaded"))
|
||||
return *i;
|
||||
}
|
||||
|
||||
@@ -263,7 +273,7 @@ static int handle_action_sleep_execute(
|
||||
if (handle == HANDLE_SLEEP) {
|
||||
HandleAction a;
|
||||
|
||||
a = handle_action_sleep_select(m->handle_action_sleep_mask);
|
||||
a = handle_action_sleep_select(m);
|
||||
if (a < 0)
|
||||
return log_warning_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
|
||||
"None of the configured sleep operations are supported, ignoring.");
|
||||
|
||||
@@ -70,7 +70,7 @@ struct HandleActionData {
|
||||
};
|
||||
|
||||
int handle_action_get_enabled_sleep_actions(HandleActionSleepMask mask, char ***ret);
|
||||
HandleAction handle_action_sleep_select(HandleActionSleepMask mask);
|
||||
HandleAction handle_action_sleep_select(Manager *m);
|
||||
|
||||
int manager_handle_action(
|
||||
Manager *m,
|
||||
|
||||
@@ -2130,7 +2130,7 @@ static int method_do_shutdown_or_sleep(
|
||||
if (action == HANDLE_SLEEP) {
|
||||
HandleAction selected;
|
||||
|
||||
selected = handle_action_sleep_select(m->handle_action_sleep_mask);
|
||||
selected = handle_action_sleep_select(m);
|
||||
if (selected < 0)
|
||||
return sd_bus_error_set(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,
|
||||
"None of the configured sleep operations are supported");
|
||||
@@ -2637,7 +2637,7 @@ static int method_can_shutdown_or_sleep(
|
||||
sd_bus_error *error) {
|
||||
|
||||
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
|
||||
bool multiple_sessions, challenge, blocked;
|
||||
bool multiple_sessions, challenge, blocked, check_unit_state = true;
|
||||
const HandleActionData *a;
|
||||
const char *result = NULL;
|
||||
uid_t uid;
|
||||
@@ -2650,10 +2650,12 @@ static int method_can_shutdown_or_sleep(
|
||||
if (action == HANDLE_SLEEP) {
|
||||
HandleAction selected;
|
||||
|
||||
selected = handle_action_sleep_select(m->handle_action_sleep_mask);
|
||||
selected = handle_action_sleep_select(m);
|
||||
if (selected < 0)
|
||||
return sd_bus_reply_method_return(message, "s", "na");
|
||||
|
||||
check_unit_state = false; /* Already handled by handle_action_sleep_select */
|
||||
|
||||
assert_se(a = handle_action_lookup(selected));
|
||||
|
||||
} else if (HANDLE_ACTION_IS_SLEEP(action)) {
|
||||
@@ -2687,7 +2689,7 @@ static int method_can_shutdown_or_sleep(
|
||||
multiple_sessions = r > 0;
|
||||
blocked = manager_is_inhibited(m, a->inhibit_what, INHIBIT_BLOCK, NULL, false, true, uid, NULL);
|
||||
|
||||
if (a->target) {
|
||||
if (check_unit_state && a->target) {
|
||||
_cleanup_free_ char *load_state = NULL;
|
||||
|
||||
r = unit_load_state(m->bus, a->target, &load_state);
|
||||
|
||||
Reference in New Issue
Block a user