]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind: return "no" if sleep operation is disabled
authorMike Yuan <me@yhndnzj.com>
Tue, 31 Oct 2023 13:08:19 +0000 (21:08 +0800)
committerMike Yuan <me@yhndnzj.com>
Thu, 16 Nov 2023 09:49:33 +0000 (17:49 +0800)
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".

src/login/logind-dbus.c

index 6ad6ef912db8facc6d4f840ea246fb9a8e6b1268..ec88c55a089534d88bd8f32f7358c67ec9155e34 100644 (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);