summaryrefslogtreecommitdiff
path: root/src/sleep
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-05-21 18:39:38 +0200
committerLennart Poettering <lennart@poettering.net>2021-05-22 11:00:04 +0200
commit3d1321117e16c108b8677ed61a842a2d50e29309 (patch)
treea5a433488e37ae84c18311c88687c598cd2a5e73 /src/sleep
parentb0c035e3c82a01037874bda1a95f8bac95de6667 (diff)
downloadsystemd-3d1321117e16c108b8677ed61a842a2d50e29309.tar.gz
sleep: if hybrid sleep fails, do regular suspend
Fixes #19550
Diffstat (limited to 'src/sleep')
-rw-r--r--src/sleep/sleep.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index 8f6bd40c5c..b05ffe72c0 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -400,10 +400,32 @@ static int run(int argc, char *argv[]) {
"Sleep operation \"%s\" is disabled by configuration, refusing.",
sleep_operation_to_string(arg_operation));
- if (arg_operation == SLEEP_SUSPEND_THEN_HIBERNATE)
- return execute_s2h(sleep_config);
- else
- return execute(sleep_config, arg_operation, NULL);
+ switch (arg_operation) {
+
+ case SLEEP_SUSPEND_THEN_HIBERNATE:
+ r = execute_s2h(sleep_config);
+ break;
+
+ case SLEEP_HYBRID_SLEEP:
+ r = execute(sleep_config, SLEEP_HYBRID_SLEEP, NULL);
+ if (r < 0) {
+ /* If we can't hybrid sleep, then let's try to suspend at least. After all, the user
+ * asked us to do both: suspend + hibernate, and it's almost certainly the
+ * hibernation that failed, hence still do the other thing, the suspend. */
+
+ log_notice("Couldn't hybrid sleep, will try to suspend instead.");
+
+ r = execute(sleep_config, SLEEP_SUSPEND, "suspend-after-failed-hybrid-sleep");
+ }
+
+ break;
+
+ default:
+ r = execute(sleep_config, arg_operation, NULL);
+ break;
+ }
+
+ return r;
}
DEFINE_MAIN_FUNCTION(run);