From: Lennart Poettering Date: Fri, 21 May 2021 16:39:38 +0000 (+0200) Subject: sleep: if hybrid sleep fails, do regular suspend X-Git-Tag: v249-rc1~174^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3d1321117e16c108b8677ed61a842a2d50e29309;p=thirdparty%2Fsystemd.git sleep: if hybrid sleep fails, do regular suspend Fixes #19550 --- diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 8f6bd40c5c7..b05ffe72c06 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);