[systemd-commits] man/logind.conf.xml src/login

Lennart Poettering lennart at kemper.freedesktop.org
Sun Oct 28 04:54:32 PDT 2012


 man/logind.conf.xml       |   15 +++++++++------
 src/login/logind-button.c |   19 ++++++++++++++++++-
 src/login/logind-button.h |    1 +
 3 files changed, 28 insertions(+), 7 deletions(-)

New commits:
commit 7654b2c2593f4d106bc01be2662c1ab8339c90e1
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sun Oct 28 12:29:27 2012 +0100

    logind: add 'lock' as possible choice for handling hw keys

diff --git a/man/logind.conf.xml b/man/logind.conf.xml
index af842b5..df15d51 100644
--- a/man/logind.conf.xml
+++ b/man/logind.conf.xml
@@ -213,13 +213,16 @@
                                 <literal>halt</literal>,
                                 <literal>kexec</literal>,
                                 <literal>suspend</literal>,
-                                <literal>hibernate</literal>, and
-                                <literal>hybrid-sleep</literal>. If
+                                <literal>hibernate</literal>,
+                                <literal>hybrid-sleep</literal> and
+                                <literal>lock</literal>. If
                                 <literal>ignore</literal> logind will
-                                never handle these keys. Otherwise the
-                                specified action will be taken in the
-                                respective event. Only input devices
-                                with the
+                                never handle these keys. If
+                                <literal>lock</literal> all running
+                                sessions will be screen
+                                locked. Otherwise the specified action
+                                will be taken in the respective
+                                event. Only input devices with the
                                 <literal>power-switch</literal> udev
                                 tag will be watched for key/lid switch
                                 events. <varname>HandlePowerKey=</varname>
diff --git a/src/login/logind-button.c b/src/login/logind-button.c
index 753d954..5fadade 100644
--- a/src/login/logind-button.c
+++ b/src/login/logind-button.c
@@ -150,6 +150,18 @@ fail:
         return r;
 }
 
+static int lock_sessions(Manager *m) {
+        Iterator i;
+        Session *session;
+
+        log_info("Locking sessions...");
+
+        HASHMAP_FOREACH(session, m->sessions, i)
+                session_send_lock(session, true);
+
+        return 1;
+}
+
 static int button_handle(
                 Button *b,
                 InhibitWhat inhibit_key,
@@ -164,7 +176,7 @@ static int button_handle(
                 [HANDLE_KEXEC] = "Rebooting via kexec...",
                 [HANDLE_SUSPEND] = "Suspending...",
                 [HANDLE_HIBERNATE] = "Hibernating...",
-                [HANDLE_HYBRID_SLEEP] = "Hibernating and suspend...",
+                [HANDLE_HYBRID_SLEEP] = "Hibernating and suspend..."
         };
 
         static const char * const target_table[_HANDLE_BUTTON_MAX] = {
@@ -195,6 +207,10 @@ static int button_handle(
                 return 0;
         }
 
+        /* Locking is handled differently from the rest. */
+        if (handle == HANDLE_LOCK)
+                return lock_sessions(b->manager);
+
         inhibit_operation = handle == HANDLE_SUSPEND || handle == HANDLE_HIBERNATE || handle == HANDLE_HYBRID_SLEEP ? INHIBIT_SLEEP : INHIBIT_SHUTDOWN;
 
         /* If the actual operation is inhibited, warn and fail */
@@ -309,6 +325,7 @@ static const char* const handle_button_table[_HANDLE_BUTTON_MAX] = {
         [HANDLE_SUSPEND] = "suspend",
         [HANDLE_HIBERNATE] = "hibernate",
         [HANDLE_HYBRID_SLEEP] = "hybrid-sleep",
+        [HANDLE_LOCK] = "lock"
 };
 DEFINE_STRING_TABLE_LOOKUP(handle_button, HandleButton);
 DEFINE_CONFIG_PARSE_ENUM(config_parse_handle_button, handle_button, HandleButton, "Failed to parse handle button setting");
diff --git a/src/login/logind-button.h b/src/login/logind-button.h
index 827a03e..b76ca32 100644
--- a/src/login/logind-button.h
+++ b/src/login/logind-button.h
@@ -33,6 +33,7 @@ typedef enum HandleButton {
         HANDLE_SUSPEND,
         HANDLE_HIBERNATE,
         HANDLE_HYBRID_SLEEP,
+        HANDLE_LOCK,
         _HANDLE_BUTTON_MAX,
         _HANDLE_BUTTON_INVALID = -1
 } HandleButton;



More information about the systemd-commits mailing list