[systemd-devel] [PATCH 4/6] logind: add inhibit support for a system-wide lock

Ben Boeckel mathstuf at gmail.com
Sat Oct 27 00:08:54 PDT 2012


---
 src/login/logind-dbus.c                    |  7 ++++---
 src/login/logind-inhibit.c                 |  6 +++++-
 src/login/logind-inhibit.h                 |  3 ++-
 src/login/org.freedesktop.login1.policy.in | 10 ++++++++++
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 5417e3b..d5fe241 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -732,8 +732,8 @@ static int bus_manager_inhibit(Manager *m, DBusConnection *connection, DBusMessa
                 goto fail;
         }
 
-        /* Delay is only supported for shutdown/sleep */
-        if (mm == INHIBIT_DELAY && (w & ~(INHIBIT_SHUTDOWN|INHIBIT_SLEEP))) {
+        /* Delay is only supported for shutdown/sleep/lock */
+        if (mm == INHIBIT_DELAY && (w & ~(INHIBIT_SHUTDOWN|INHIBIT_SLEEP|INHIBIT_LOCK))) {
                 r = -EINVAL;
                 goto fail;
         }
@@ -745,7 +745,8 @@ static int bus_manager_inhibit(Manager *m, DBusConnection *connection, DBusMessa
                           w == INHIBIT_HANDLE_POWER_KEY     ? "org.freedesktop.login1.inhibit-handle-power-key" :
                           w == INHIBIT_HANDLE_SUSPEND_KEY   ? "org.freedesktop.login1.inhibit-handle-suspend-key" :
                           w == INHIBIT_HANDLE_HIBERNATE_KEY ? "org.freedesktop.login1.inhibit-handle-hibernate-key" :
-                                                              "org.freedesktop.login1.inhibit-handle-lid-switch",
+                          w == INHIBIT_HANDLE_LID_SWITCH    ? "org.freedesktop.login1.inhibit-handle-lid-switch" :
+                                                              (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-lock"     : "org.freedesktop.login1.inhibit-delay-lock"),
                           false, NULL, error);
         if (r < 0)
                 goto fail;
diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c
index f1b9cca..6b4dc04 100644
--- a/src/login/logind-inhibit.c
+++ b/src/login/logind-inhibit.c
@@ -403,7 +403,7 @@ bool manager_is_inhibited(
 }
 
 const char *inhibit_what_to_string(InhibitWhat w) {
-        static __thread char buffer[97];
+        static __thread char buffer[102];
         char *p;
 
         if (w < 0 || w >= _INHIBIT_WHAT_MAX)
@@ -424,6 +424,8 @@ const char *inhibit_what_to_string(InhibitWhat w) {
                 p = stpcpy(p, "handle-hibernate-key:");
         if (w & INHIBIT_HANDLE_LID_SWITCH)
                 p = stpcpy(p, "handle-lid-switch:");
+        if (w & INHIBIT_LOCK)
+                p = stpcpy(p, "lock:");
 
         if (p > buffer)
                 *(p-1) = 0;
@@ -453,6 +455,8 @@ InhibitWhat inhibit_what_from_string(const char *s) {
                         what |= INHIBIT_HANDLE_HIBERNATE_KEY;
                 else if (l == 17 && strncmp(w, "handle-lid-switch", l) == 0)
                         what |= INHIBIT_HANDLE_LID_SWITCH;
+                else if (l == 4 && strncmp(w, "lock", l) == 0)
+                        what |= INHIBIT_LOCK;
                 else
                         return _INHIBIT_WHAT_INVALID;
         }
diff --git a/src/login/logind-inhibit.h b/src/login/logind-inhibit.h
index 4c158ee..7081faf 100644
--- a/src/login/logind-inhibit.h
+++ b/src/login/logind-inhibit.h
@@ -35,7 +35,8 @@ typedef enum InhibitWhat {
         INHIBIT_HANDLE_SUSPEND_KEY = 16,
         INHIBIT_HANDLE_HIBERNATE_KEY = 32,
         INHIBIT_HANDLE_LID_SWITCH = 64,
-        _INHIBIT_WHAT_MAX = 128,
+        INHIBIT_LOCK = 128,
+        _INHIBIT_WHAT_MAX = 256,
         _INHIBIT_WHAT_INVALID = -1
 } InhibitWhat;
 
diff --git a/src/login/org.freedesktop.login1.policy.in b/src/login/org.freedesktop.login1.policy.in
index 57dfb2a..131c846 100644
--- a/src/login/org.freedesktop.login1.policy.in
+++ b/src/login/org.freedesktop.login1.policy.in
@@ -66,6 +66,16 @@
                 </defaults>
         </action>
 
+        <action id="org.freedesktop.login1.inhibit-lock">
+                <_description>Allow applications to inhibit automatic session locking</_description>
+                <_message>Authentication is required to allow an application to inhibit automatic session locking.</_message>
+                <defaults>
+                        <allow_any>no</allow_any>
+                        <allow_inactive>no</allow_inactive>
+                        <allow_active>yes</allow_active>
+                </defaults>
+        </action>
+
         <action id="org.freedesktop.login1.inhibit-handle-power-key">
                 <_description>Allow applications to inhibit system handling of the power key</_description>
                 <_message>Authentication is required to allow an application to inhibit system handling of the power key.</_message>
-- 
1.7.12.1



More information about the systemd-devel mailing list