chiark / gitweb /
man: document that assignemnts of devices to seats are persistent
[elogind.git] / src / login / logind-dbus.c
index a2ead8609bd1158e62dd81f88d20e56ec052e296..af62d8782117796423eca411fefd54ec0e9b18c6 100644 (file)
@@ -31,6 +31,8 @@
 #include "path-util.h"
 #include "polkit.h"
 #include "special.h"
+#include "systemd/sd-id128.h"
+#include "systemd/sd-messages.h"
 
 #define BUS_MANAGER_INTERFACE                                           \
         " <interface name=\"org.freedesktop.login1.Manager\">\n"        \
         "  <method name=\"UnlockSession\">\n"                           \
         "   <arg name=\"id\" type=\"s\" direction=\"in\"/>\n"           \
         "  </method>\n"                                                 \
+        "  <method name=\"LockSessions\"/>\n"                           \
         "  <method name=\"KillSession\">\n"                             \
         "   <arg name=\"id\" type=\"s\" direction=\"in\"/>\n"           \
         "   <arg name=\"who\" type=\"s\" direction=\"in\"/>\n"          \
@@ -967,36 +970,21 @@ static int have_multiple_sessions(
 }
 
 static int send_start_unit(DBusConnection *connection, const char *unit_name, DBusError *error) {
-        DBusMessage *message, *reply;
         const char *mode = "replace";
 
-        assert(connection);
         assert(unit_name);
 
-        message = dbus_message_new_method_call(
+        return bus_method_call_with_reply (
+                        connection,
                         "org.freedesktop.systemd1",
                         "/org/freedesktop/systemd1",
                         "org.freedesktop.systemd1.Manager",
-                        "StartUnit");
-        if (!message)
-                return -ENOMEM;
-
-        if (!dbus_message_append_args(message,
-                                      DBUS_TYPE_STRING, &unit_name,
-                                      DBUS_TYPE_STRING, &mode,
-                                      DBUS_TYPE_INVALID)) {
-                dbus_message_unref(message);
-                return -ENOMEM;
-        }
-
-        reply = dbus_connection_send_with_reply_and_block(connection, message, -1, error);
-        dbus_message_unref(message);
-
-        if (!reply)
-                return -EIO;
-
-        dbus_message_unref(reply);
-        return 0;
+                        "StartUnit",
+                        NULL,
+                        NULL,
+                        DBUS_TYPE_STRING, &unit_name,
+                        DBUS_TYPE_STRING, &mode,
+                        DBUS_TYPE_INVALID);
 }
 
 static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) {
@@ -1152,6 +1140,42 @@ finish:
         return 0;
 }
 
+static int bus_manager_log_shutdown(
+                Manager *m,
+                InhibitWhat w,
+                const char *unit_name) {
+
+        const char *p, *q;
+
+        assert(m);
+        assert(unit_name);
+
+        if (w != INHIBIT_SHUTDOWN)
+                return 0;
+
+        if (streq(unit_name, SPECIAL_POWEROFF_TARGET)) {
+                p = "MESSAGE=System is powering down.";
+                q = "SHUTDOWN=power-off";
+        } else if (streq(unit_name, SPECIAL_HALT_TARGET)) {
+                p = "MESSAGE=System is halting.";
+                q = "SHUTDOWN=halt";
+        } else if (streq(unit_name, SPECIAL_REBOOT_TARGET)) {
+                p = "MESSAGE=System is rebooting.";
+                q = "SHUTDOWN=reboot";
+        } else if (streq(unit_name, SPECIAL_KEXEC_TARGET)) {
+                p = "MESSAGE=System is rebooting with kexec.";
+                q = "SHUTDOWN=kexec";
+        } else {
+                p = "MESSAGE=System is shutting down.";
+                q = NULL;
+        }
+
+        return log_struct(LOG_NOTICE,
+                          "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SHUTDOWN),
+                          p,
+                          q, NULL);
+}
+
 int bus_manager_shutdown_or_sleep_now_or_later(
                 Manager *m,
                 const char *unit_name,
@@ -1174,10 +1198,13 @@ int bus_manager_shutdown_or_sleep_now_or_later(
                 /* Shutdown is delayed, keep in mind what we
                  * want to do, and start a timeout */
                 r = delay_shutdown_or_sleep(m, w, unit_name);
-        else
+        else {
+                bus_manager_log_shutdown(m, w, unit_name);
+
                 /* Shutdown is not delayed, execute it
                  * immediately */
                 r = send_start_unit(m->bus, unit_name, error);
+        }
 
         return r;
 }
@@ -1745,6 +1772,18 @@ static DBusHandlerResult manager_message_handler(
                 if (!reply)
                         goto oom;
 
+        } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "LockSessions")) {
+                Session *session;
+                Iterator i;
+
+                HASHMAP_FOREACH(session, m->sessions, i)
+                        if (session_send_lock(session, true) < 0)
+                                goto oom;
+
+                reply = dbus_message_new_method_return(message);
+                if (!reply)
+                        goto oom;
+
         } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "KillSession")) {
                 const char *swho;
                 int32_t signo;
@@ -2258,6 +2297,8 @@ int manager_dispatch_delayed(Manager *manager) {
         if (delayed)
                 return 0;
 
+        bus_manager_log_shutdown(manager, manager->delayed_what, manager->delayed_unit);
+
         /* Reset delay data */
         unit_name = manager->delayed_unit;
         manager->delayed_unit = NULL;