logind: return "no" if sleep operation is disabled

According to org.freedesktop.login1:

> If "na" is returned, the operation is not available because
> hardware, kernel, or drivers do not support it. If "yes" is
> returned, the operation is supported and the user may execute
> the operation without further authentication. If "no" is returned,
> the operation is available but the user is not allowed to execute
> the operation.

Therefore, we should return "no" if sleep is explicitly disabled,
otherwise we return "na".
This commit is contained in:
Mike Yuan
2023-10-31 21:08:19 +08:00
parent 15b5bb6262
commit 51eeeb7bde

View File

@@ -2543,11 +2543,13 @@ static int method_can_shutdown_or_sleep(
assert(a);
if (a->sleep_operation >= 0) {
r = sleep_supported(a->sleep_operation);
SleepSupport support;
r = sleep_supported_full(a->sleep_operation, &support);
if (r < 0)
return r;
if (r == 0)
return sd_bus_reply_method_return(message, "s", "na");
return sd_bus_reply_method_return(message, "s", support == SLEEP_DISABLED ? "no" : "na");
}
r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_EUID, &creds);