summaryrefslogtreecommitdiff
path: root/src/login/logind-action.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-04-11 10:26:27 +0200
committerGitHub <noreply@github.com>2018-04-11 10:26:27 +0200
commitb667d50d3443be7fd861d319b5acd525aa15329c (patch)
treed9f1f328c2fa39b7efc7513b3b36f224ae94ea13 /src/login/logind-action.c
parentcf45dd36282368d5cdf757cac2cf1fc2b562dab2 (diff)
parent4638cd39af495d89014c31b449f62a2618c390f3 (diff)
downloadsystemd-b667d50d3443be7fd861d319b5acd525aa15329c.tar.gz
Merge pull request #8700 from keszybz/hibernation
Various improvements related to hibernation
Diffstat (limited to 'src/login/logind-action.c')
-rw-r--r--src/login/logind-action.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/login/logind-action.c b/src/login/logind-action.c
index 99138edfe4..81a30b73c8 100644
--- a/src/login/logind-action.c
+++ b/src/login/logind-action.c
@@ -20,6 +20,24 @@
#include "terminal-util.h"
#include "user-util.h"
+const char* manager_target_for_action(HandleAction handle) {
+ static const char * const target_table[_HANDLE_ACTION_MAX] = {
+ [HANDLE_POWEROFF] = SPECIAL_POWEROFF_TARGET,
+ [HANDLE_REBOOT] = SPECIAL_REBOOT_TARGET,
+ [HANDLE_HALT] = SPECIAL_HALT_TARGET,
+ [HANDLE_KEXEC] = SPECIAL_KEXEC_TARGET,
+ [HANDLE_SUSPEND] = SPECIAL_SUSPEND_TARGET,
+ [HANDLE_HIBERNATE] = SPECIAL_HIBERNATE_TARGET,
+ [HANDLE_HYBRID_SLEEP] = SPECIAL_HYBRID_SLEEP_TARGET,
+ [HANDLE_SUSPEND_THEN_HIBERNATE] = SPECIAL_SUSPEND_THEN_HIBERNATE_TARGET,
+ };
+
+ assert(handle >= 0);
+ if (handle < (ssize_t) ELEMENTSOF(target_table))
+ return target_table[handle];
+ return NULL;
+}
+
int manager_handle_action(
Manager *m,
InhibitWhat inhibit_key,
@@ -38,21 +56,11 @@ int manager_handle_action(
[HANDLE_SUSPEND_THEN_HIBERNATE] = "Suspending, then hibernating...",
};
- static const char * const target_table[_HANDLE_ACTION_MAX] = {
- [HANDLE_POWEROFF] = SPECIAL_POWEROFF_TARGET,
- [HANDLE_REBOOT] = SPECIAL_REBOOT_TARGET,
- [HANDLE_HALT] = SPECIAL_HALT_TARGET,
- [HANDLE_KEXEC] = SPECIAL_KEXEC_TARGET,
- [HANDLE_SUSPEND] = SPECIAL_SUSPEND_TARGET,
- [HANDLE_HIBERNATE] = SPECIAL_HIBERNATE_TARGET,
- [HANDLE_HYBRID_SLEEP] = SPECIAL_HYBRID_SLEEP_TARGET,
- [HANDLE_SUSPEND_THEN_HIBERNATE] = SPECIAL_SUSPEND_THEN_HIBERNATE_TARGET,
- };
-
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
InhibitWhat inhibit_operation;
Inhibitor *offending = NULL;
bool supported;
+ const char *target;
int r;
assert(m);
@@ -84,7 +92,6 @@ int manager_handle_action(
/* Locking is handled differently from the rest. */
if (handle == HANDLE_LOCK) {
-
if (!is_edge)
return 0;
@@ -116,6 +123,8 @@ int manager_handle_action(
return -EALREADY;
}
+ assert_se(target = manager_target_for_action(handle));
+
inhibit_operation = IN_SET(handle, HANDLE_SUSPEND, HANDLE_HIBERNATE,
HANDLE_HYBRID_SLEEP,
HANDLE_SUSPEND_THEN_HIBERNATE) ? INHIBIT_SLEEP : INHIBIT_SHUTDOWN;
@@ -147,7 +156,7 @@ int manager_handle_action(
log_info("%s", message_table[handle]);
- r = bus_manager_shutdown_or_sleep_now_or_later(m, target_table[handle], inhibit_operation, &error);
+ r = bus_manager_shutdown_or_sleep_now_or_later(m, target, inhibit_operation, &error);
if (r < 0) {
log_error("Failed to execute operation: %s", bus_error_message(&error, r));
return r;
@@ -166,7 +175,7 @@ static const char* const handle_action_table[_HANDLE_ACTION_MAX] = {
[HANDLE_HIBERNATE] = "hibernate",
[HANDLE_HYBRID_SLEEP] = "hybrid-sleep",
[HANDLE_SUSPEND_THEN_HIBERNATE] = "suspend-then-hibernate",
- [HANDLE_LOCK] = "lock"
+ [HANDLE_LOCK] = "lock",
};
DEFINE_STRING_TABLE_LOOKUP(handle_action, HandleAction);