]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sleep: if hybrid sleep fails, do regular suspend
authorLennart Poettering <lennart@poettering.net>
Fri, 21 May 2021 16:39:38 +0000 (18:39 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 22 May 2021 09:00:04 +0000 (11:00 +0200)
Fixes #19550

src/sleep/sleep.c

index 8f6bd40c5c791f10d8b7acc07fe1a58da62aab68..b05ffe72c06345af699fc2c3db1db4d6655ba62f 100644 (file)
@@ -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);