Skip to content

Commit

Permalink
Merge pull request #29382 from YHNdnzj/sleep-round-two
Browse files Browse the repository at this point in the history
shared/sleep-config,hibernate-util: cleanup round two
  • Loading branch information
bluca authored Oct 21, 2023
2 parents bf25cf6 + 805deec commit 242b4be
Show file tree
Hide file tree
Showing 9 changed files with 535 additions and 477 deletions.
10 changes: 5 additions & 5 deletions src/login/logind-action.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,20 @@ int manager_handle_action(
}

if (handle == HANDLE_SUSPEND)
supported = can_sleep(SLEEP_SUSPEND) > 0;
supported = sleep_supported(SLEEP_SUSPEND) > 0;
else if (handle == HANDLE_HIBERNATE)
supported = can_sleep(SLEEP_HIBERNATE) > 0;
supported = sleep_supported(SLEEP_HIBERNATE) > 0;
else if (handle == HANDLE_HYBRID_SLEEP)
supported = can_sleep(SLEEP_HYBRID_SLEEP) > 0;
supported = sleep_supported(SLEEP_HYBRID_SLEEP) > 0;
else if (handle == HANDLE_SUSPEND_THEN_HIBERNATE)
supported = can_sleep(SLEEP_SUSPEND_THEN_HIBERNATE) > 0;
supported = sleep_supported(SLEEP_SUSPEND_THEN_HIBERNATE) > 0;
else if (handle == HANDLE_KEXEC)
supported = access(KEXEC, X_OK) >= 0;
else
supported = true;

if (!supported && HANDLE_ACTION_IS_SLEEP(handle) && handle != HANDLE_SUSPEND) {
supported = can_sleep(SLEEP_SUSPEND) > 0;
supported = sleep_supported(SLEEP_SUSPEND) > 0;
if (supported) {
log_notice("Requested %s operation is not supported, using regular suspend instead.",
handle_action_to_string(handle));
Expand Down
44 changes: 33 additions & 11 deletions src/login/logind-dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1924,16 +1924,38 @@ static int method_do_shutdown_or_sleep(
"There's already a shutdown or sleep operation in progress");

if (a->sleep_operation >= 0) {
r = can_sleep(a->sleep_operation);
if (r == -ENOSPC)
return sd_bus_error_set(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,
"Not enough suitable swap space for hibernation available on compatible block devices and file systems");
if (r == 0)
return sd_bus_error_setf(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,
"Sleep verb \"%s\" not supported",
sleep_operation_to_string(a->sleep_operation));
SleepSupport support;

r = sleep_supported_full(a->sleep_operation, &support);
if (r < 0)
return r;
if (r == 0)
switch (support) {

case SLEEP_DISABLED:
return sd_bus_error_setf(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,
"Sleep verb '%s' is disabled by config",
sleep_operation_to_string(a->sleep_operation));

case SLEEP_NOT_CONFIGURED:
case SLEEP_STATE_OR_MODE_NOT_SUPPORTED:
case SLEEP_ALARM_NOT_SUPPORTED:
return sd_bus_error_setf(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,
"Sleep verb '%s' is not configured or configuration is not supported by kernel",
sleep_operation_to_string(a->sleep_operation));

case SLEEP_RESUME_NOT_SUPPORTED:
return sd_bus_error_set(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,
"Not running on EFI and resume= is not set. No available method to resume from hibernation");

case SLEEP_NOT_ENOUGH_SWAP_SPACE:
return sd_bus_error_set(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,
"Not enough suitable swap space for hibernation available on compatible block devices and file systems");

default:
assert_not_reached();

}
}

r = verify_shutdown_creds(m, message, a, flags, error);
Expand Down Expand Up @@ -2395,11 +2417,11 @@ static int method_can_shutdown_or_sleep(
assert(a);

if (a->sleep_operation >= 0) {
r = can_sleep(a->sleep_operation);
if (IN_SET(r, 0, -ENOSPC))
return sd_bus_reply_method_return(message, "s", "na");
r = sleep_supported(a->sleep_operation);
if (r < 0)
return r;
if (r == 0)
return sd_bus_reply_method_return(message, "s", "na");
}

r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_EUID, &creds);
Expand Down
Loading

0 comments on commit 242b4be

Please sign in to comment.