[systemd-commits] 5 commits - TODO man/loginctl.xml src/login

Lennart Poettering lennart at kemper.freedesktop.org
Wed Jan 23 20:47:45 PST 2013


 TODO                      |   24 +++++-------
 man/loginctl.xml          |    8 ++--
 src/login/loginctl.c      |    6 ++-
 src/login/logind-action.c |    9 ++++
 src/login/logind-dbus.c   |   90 ++++++++++++++++++++++++++++++++++++----------
 src/login/logind.c        |    2 +
 src/login/logind.h        |    5 ++
 src/login/sysfs-show.c    |    9 +++-
 8 files changed, 114 insertions(+), 39 deletions(-)

New commits:
commit d239d84aa384a532e1056ec1d09fef16d843b8eb
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jan 24 05:47:37 2013 +0100

    loginctl: show seat master and uaccess devices in seat-status output

diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c
index d113ec3..da34c3a 100644
--- a/src/login/sysfs-show.c
+++ b/src/login/sysfs-show.c
@@ -45,6 +45,7 @@ static int show_sysfs_one(
                 struct udev_device *d;
                 const char *sn, *name, *sysfs, *subsystem, *sysname;
                 char *l, *k;
+                bool is_master, uaccess;
 
                 sysfs = udev_list_entry_get_name(*item);
                 if (!path_startswith(sysfs, sub))
@@ -60,13 +61,16 @@ static int show_sysfs_one(
                 if (isempty(sn))
                         sn = "seat0";
 
-                /* fixme, also check for tag 'seat' here */
+                /* Explicitly also check for tag 'seat' here */
                 if (!streq(seat, sn) || !udev_device_has_tag(d, "seat")) {
                         udev_device_unref(d);
                         *item = udev_list_entry_get_next(*item);
                         continue;
                 }
 
+                is_master = udev_device_has_tag(d, "seat-master");
+                uaccess = udev_device_has_tag(d, "uaccess");
+
                 name = udev_device_get_sysattr_value(d, "name");
                 if (!name)
                         name = udev_device_get_sysattr_value(d, "id");
@@ -110,7 +114,8 @@ static int show_sysfs_one(
                 free(k);
 
                 if (asprintf(&l,
-                             "(%s:%s)%s%s%s",
+                             "%s%s%s:%s%s%s%s",
+                             is_master ? "[MASTER] " : "", uaccess ? "[ACL] " : "",
                              subsystem, sysname,
                              name ? " \"" : "", name ? name : "", name ? "\"" : "") < 0) {
                         udev_device_unref(d);

commit bfb7ec0ebab18a0bc8a99997f541c980a323c867
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jan 24 05:33:33 2013 +0100

    update TODO

diff --git a/TODO b/TODO
index e4020a4..0bfbe1b 100644
--- a/TODO
+++ b/TODO
@@ -20,6 +20,17 @@ Fedora 19:
 
 Features:
 
+* unify killing logic of service, socket, mount, swap units
+
+* downgrade selinux log messages
+
+* logind: document new Resume signal and UnlockSessions call in wiki
+
+* logind: when a delay lock is taken, delay method return until we are
+  out of a suspend cycle
+
+* in "loginctl seat-status" we should mark the master device with a "*" or so
+
 * if we have systemd-analyze in C "systemctl dot" should move there too
 
 * fsck hookup for the ESP mount is missing
@@ -31,19 +42,12 @@ Features:
 
 * write man page for efi boot generator
 
-* document bootloader interface in wiki
-
 * link runlevel targets on install only if sysv compat is enabled
 
-* logind: when executing sleep/shutdown job, keep track of its id, and
-  as long as the job is running refuse any further operation.
-
 * maybe not install getty at tty1.service symlink in /etc but in /usr?
 
 * re-enable "make check" for gtk-doc (broken for unknown reason)
 
-* logind: make PrepareForSuspend(false) an official api for notification of resumes
-
 * "systemctl disable" on a static unit prints no message and does
   nothing. "systemctl enable" does nothing, and gives a bad message
   about it. Should fix both to print nice actionable messages.
@@ -51,8 +55,6 @@ Features:
 * fstab: add new mount option x-systemd-after=/foobar/waldo to allow manual dependencies to other mount points
   https://bugzilla.redhat.com/show_bug.cgi?id=812826
 
-* add "loginctl unlock-sessions" as counterpart for "loginctl lock-sessions"
-
 * cgroup attrs:
   - don't filter out duplicate settings
   - support high-level cgroup setting syntax in systemctl. Example: "systemctl set-cgroup-attr MemoryLimit 5K"
@@ -68,8 +70,6 @@ Features:
 
 * logind: optionally, ignore idle-hint logic for autosuspend, block suspend as long as a session is around
 
-* service: when killing a service with SIGKILL always kill all processes, even if for SIGTERM we only killed the main process
-
 * exec: when deinitializating a tty device fix the perms and group, too, not only when initializing. Set access mode/gid to 0620/tty.
 
 * DeviceAllow/DeviceDeny: disallow everything by default, but whitelist /dev/zero, /dev/null and friends
@@ -119,8 +119,6 @@ Features:
   mode, it will never touch the RTC if the no reliable time source is active or the
   user did not request anything like it.
 
-* When we begin with system shutdown all kind of suspend/hibernation should be prohibited until shutdown/reboot
-
 * When we update the kernel all kind of hibernation should be prohibited until shutdown/reboot
 
 * hwdb:

commit b61600291e3bbc51482bbb9823ccd48f03c130da
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jan 24 05:29:37 2013 +0100

    logind: add UnlockSessions() clal to complement LockSessions()

diff --git a/man/loginctl.xml b/man/loginctl.xml
index 8a20d18..9d082cf 100644
--- a/man/loginctl.xml
+++ b/man/loginctl.xml
@@ -251,10 +251,12 @@
 
                         <varlistentry>
                                 <term><command>lock-sessions</command></term>
+                                <term><command>unlock-sessions</command></term>
 
-                                <listitem><para>Activate the screen
-                                lock on all current sessions
-                                supporting it.</para></listitem>
+                                <listitem><para>Activates/deactivates
+                                the screen lock on all current
+                                sessions supporting
+                                it.</para></listitem>
                         </varlistentry>
 
                         <varlistentry>
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index 0e57e08..473c77b 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -1287,6 +1287,8 @@ static int flush_devices(DBusConnection *bus, char **args, unsigned n) {
 }
 
 static int lock_sessions(DBusConnection *bus, char **args, unsigned n) {
+        assert(args);
+
         polkit_agent_open_if_enabled();
 
         return bus_method_call_with_reply (
@@ -1294,7 +1296,7 @@ static int lock_sessions(DBusConnection *bus, char **args, unsigned n) {
                         "org.freedesktop.login1",
                         "/org/freedesktop/login1",
                         "org.freedesktop.login1.Manager",
-                        "LockSessions",
+                        streq(args[0], "lock-sessions") ? "LockSessions" : "UnlockSessions",
                         NULL,
                         NULL,
                         DBUS_TYPE_INVALID);
@@ -1348,6 +1350,7 @@ static int help(void) {
                "  lock-session [ID...]            Screen lock one or more sessions\n"
                "  unlock-session [ID...]          Screen unlock one or more sessions\n"
                "  lock-sessions                   Screen lock all current sessions\n"
+               "  unlock-sessions                 Screen unlock all current sessions\n"
                "  terminate-session [ID...]       Terminate one or more sessions\n"
                "  kill-session [ID...]            Send signal to processes of a session\n"
                "  list-users                      List users\n"
@@ -1496,6 +1499,7 @@ static int loginctl_main(DBusConnection *bus, int argc, char *argv[], DBusError
                 { "lock-session",          MORE,   2, activate         },
                 { "unlock-session",        MORE,   2, activate         },
                 { "lock-sessions",         EQUAL,  1, lock_sessions    },
+                { "unlock-sessions",       EQUAL,  1, lock_sessions    },
                 { "terminate-session",     MORE,   2, activate         },
                 { "kill-session",          MORE,   2, kill_session     },
                 { "list-users",            EQUAL,  1, list_users       },
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 1717584..0960aab 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -102,6 +102,7 @@
         "   <arg name=\"id\" type=\"s\" direction=\"in\"/>\n"           \
         "  </method>\n"                                                 \
         "  <method name=\"LockSessions\"/>\n"                           \
+        "  <method name=\"UnlockSessions\"/>\n"                         \
         "  <method name=\"KillSession\">\n"                             \
         "   <arg name=\"id\" type=\"s\" direction=\"in\"/>\n"           \
         "   <arg name=\"who\" type=\"s\" direction=\"in\"/>\n"          \
@@ -1853,8 +1854,10 @@ static DBusHandlerResult manager_message_handler(
                 if (!reply)
                         goto oom;
 
-        } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "LockSessions")) {
-                r = session_send_lock_all(m, true);
+        } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "LockSessions") ||
+                   dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "UnlockSessions")) {
+
+                r = session_send_lock_all(m, streq(dbus_message_get_member(message), "LockSessions"));
                 if (r < 0)
                         bus_send_error_reply(connection, message, NULL, r);
 

commit ee17c9281d3c208ca3f4fadd800990e61e8fd4f2
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jan 24 05:15:36 2013 +0100

    logind: send Resumed() signal after we come back from suspend/hibernate/hybrid-sleep
    
    This allows clients to get asynchronous notifications for user-requested
    suspend/hibernate cycles. Kernel-triggered automatic suspending is not
    covered.

diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 0ff20fa..1717584 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -197,6 +197,7 @@
         "   <arg name=\"id\" type=\"s\"/>\n"                            \
         "   <arg name=\"path\" type=\"o\"/>\n"                          \
         "  </signal>\n"                                                 \
+        "  <signal name=\"Resumed\"/>\n"                                \
         "  <signal name=\"PrepareForShutdown\">\n"                      \
         "   <arg name=\"active\" type=\"b\"/>\n"                        \
         "  </signal>\n"                                                 \
@@ -990,7 +991,7 @@ static int have_multiple_sessions(
         return false;
 }
 
-static int send_start_unit(Manager *m, const char *unit_name, DBusError *error) {
+static int send_start_unit(Manager *m, const char *unit_name, bool send_resumed, DBusError *error) {
         _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         const char *mode = "replace", *p;
         int r;
@@ -1026,6 +1027,7 @@ static int send_start_unit(Manager *m, const char *unit_name, DBusError *error)
 
         free(m->action_job);
         m->action_job = c;
+        m->send_resumed_after_action_job = send_resumed;
 
         return 0;
 }
@@ -1037,8 +1039,7 @@ static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) {
         };
 
         dbus_bool_t active = _active;
-        DBusMessage *message;
-        int r = 0;
+        _cleanup_dbus_message_unref_ DBusMessage *message = NULL;
 
         assert(m);
         assert(w >= 0);
@@ -1051,10 +1052,9 @@ static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) {
 
         if (!dbus_message_append_args(message, DBUS_TYPE_BOOLEAN, &active, DBUS_TYPE_INVALID) ||
             !dbus_connection_send(m->bus, message, NULL))
-                r = -ENOMEM;
+                return -ENOMEM;
 
-        dbus_message_unref(message);
-        return r;
+        return 0;
 }
 
 static int delay_shutdown_or_sleep(Manager *m, InhibitWhat w, const char *unit_name) {
@@ -1263,7 +1263,7 @@ int bus_manager_shutdown_or_sleep_now_or_later(
 
                 /* Shutdown is not delayed, execute it
                  * immediately */
-                r = send_start_unit(m, unit_name, error);
+                r = send_start_unit(m, unit_name, w & INHIBIT_SLEEP, error);
         }
 
         return r;
@@ -2369,6 +2369,14 @@ DBusHandlerResult bus_message_filter(
                         log_info("Action is complete, result is '%s'.", result);
                         free(m->action_job);
                         m->action_job = NULL;
+
+                        if (m->send_resumed_after_action_job) {
+                                _cleanup_dbus_message_unref_ DBusMessage *s = NULL;
+
+                                s = dbus_message_new_signal("/org/freedesktop/login1", "org.freedesktop.login1.Manager", "Resumed");
+                                if (s)
+                                        dbus_connection_send(m->bus, s, NULL);
+                        }
                 }
         }
 
@@ -2428,7 +2436,7 @@ int manager_dispatch_delayed(Manager *manager) {
 
         /* Actually do the shutdown */
         dbus_error_init(&error);
-        r = send_start_unit(manager, unit_name, &error);
+        r = send_start_unit(manager, unit_name, manager->delayed_what & INHIBIT_SLEEP, &error);
         if (r < 0) {
                 log_warning("Failed to send delayed message: %s", bus_error_message_or_strerror(&error, -r));
                 dbus_error_free(&error);
diff --git a/src/login/logind.h b/src/login/logind.h
index fe6ea0f..7a0f8f2 100644
--- a/src/login/logind.h
+++ b/src/login/logind.h
@@ -101,6 +101,7 @@ struct Manager {
         usec_t inhibit_delay_max;
 
         char* action_job;
+        bool send_resumed_after_action_job;
 
         int idle_action_fd; /* the timer_fd */
         usec_t idle_action_usec;

commit af9792ac7f39354f80e9006c42c2400c5e41c447
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jan 24 04:56:44 2013 +0100

    logind: only allow one shutdown/sleep action to be queued at the same time
    
    This should make sure that closing the lid while shutting down won't
    suspend the machine but will simply cause the shutdown to complete.

diff --git a/src/login/logind-action.c b/src/login/logind-action.c
index e1517d6..a796ebe 100644
--- a/src/login/logind-action.c
+++ b/src/login/logind-action.c
@@ -56,10 +56,15 @@ int manager_handle_action(
         DBusError error;
         int r;
         InhibitWhat inhibit_operation;
-        bool supported = true;
+        bool supported;
 
         assert(m);
 
+        if (m->action_job || m->delayed_unit) {
+                log_debug("Action already in progress, ignoring.");
+                return -EALREADY;
+        }
+
         /* If the key handling is turned off, don't do anything */
         if (handle == HANDLE_IGNORE) {
                 log_debug("Refusing operation, as it is turned off.");
@@ -74,6 +79,8 @@ int manager_handle_action(
                 supported = can_sleep("disk") > 0 && can_sleep_disk("suspend") > 0;
         else if (handle == HANDLE_KEXEC)
                 supported = access("/sbin/kexec", X_OK) >= 0;
+        else
+                supported = true;
 
         if (!supported) {
                 log_warning("Requested operation not supported, ignoring.");
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index d64debe..0ff20fa 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -990,22 +990,44 @@ static int have_multiple_sessions(
         return false;
 }
 
-static int send_start_unit(DBusConnection *connection, const char *unit_name, DBusError *error) {
-        const char *mode = "replace";
+static int send_start_unit(Manager *m, const char *unit_name, DBusError *error) {
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
+        const char *mode = "replace", *p;
+        int r;
+        char *c;
 
+        assert(m);
         assert(unit_name);
 
-        return bus_method_call_with_reply (
-                        connection,
+        r = bus_method_call_with_reply(
+                        m->bus,
                         "org.freedesktop.systemd1",
                         "/org/freedesktop/systemd1",
                         "org.freedesktop.systemd1.Manager",
                         "StartUnit",
-                        NULL,
-                        NULL,
+                        &reply,
+                        error,
                         DBUS_TYPE_STRING, &unit_name,
                         DBUS_TYPE_STRING, &mode,
                         DBUS_TYPE_INVALID);
+        if (r < 0)
+                return r;
+
+        if (!dbus_message_get_args(
+                            reply,
+                            error,
+                            DBUS_TYPE_OBJECT_PATH, &p,
+                            DBUS_TYPE_INVALID))
+                return -EINVAL;
+
+        c = strdup(p);
+        if (!c)
+                return -ENOMEM;
+
+        free(m->action_job);
+        m->action_job = c;
+
+        return 0;
 }
 
 static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) {
@@ -1226,6 +1248,7 @@ int bus_manager_shutdown_or_sleep_now_or_later(
         assert(unit_name);
         assert(w >= 0);
         assert(w <= _INHIBIT_WHAT_MAX);
+        assert(!m->action_job);
 
         delayed =
                 m->inhibit_delay_max > 0 &&
@@ -1240,7 +1263,7 @@ int bus_manager_shutdown_or_sleep_now_or_later(
 
                 /* Shutdown is not delayed, execute it
                  * immediately */
-                r = send_start_unit(m->bus, unit_name, error);
+                r = send_start_unit(m, unit_name, error);
         }
 
         return r;
@@ -1278,6 +1301,9 @@ static int bus_manager_do_shutdown_or_sleep(
         assert(error);
         assert(_reply);
 
+        if (m->action_job || m->delayed_unit)
+                return -EALREADY;
+
         if (!dbus_message_get_args(
                             message,
                             error,
@@ -2327,6 +2353,23 @@ DBusHandlerResult bus_message_filter(
                         log_error("Failed to parse Released message: %s", bus_error_message(&error));
                 else
                         manager_cgroup_notify_empty(m, cgroup);
+
+        } else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Manager", "JobRemoved")) {
+                uint32_t id;
+                const char *path, *result, *unit;
+
+                if (!dbus_message_get_args(message, &error,
+                                           DBUS_TYPE_UINT32, &id,
+                                           DBUS_TYPE_OBJECT_PATH, &path,
+                                           DBUS_TYPE_STRING, &unit,
+                                           DBUS_TYPE_STRING, &result,
+                                           DBUS_TYPE_INVALID))
+                        log_error("Failed to parse JobRemoved message: %s", bus_error_message(&error));
+                else if (m->action_job && streq(m->action_job, path)) {
+                        log_info("Action is complete, result is '%s'.", result);
+                        free(m->action_job);
+                        m->action_job = NULL;
+                }
         }
 
         dbus_error_free(&error);
@@ -2376,21 +2419,21 @@ int manager_dispatch_delayed(Manager *manager) {
 
         bus_manager_log_shutdown(manager, manager->delayed_what, manager->delayed_unit);
 
+        /* Tell people about it */
+        send_prepare_for(manager, manager->delayed_what, false);
+
         /* Reset delay data */
         unit_name = manager->delayed_unit;
         manager->delayed_unit = NULL;
 
         /* Actually do the shutdown */
         dbus_error_init(&error);
-        r = send_start_unit(manager->bus, unit_name, &error);
+        r = send_start_unit(manager, unit_name, &error);
         if (r < 0) {
                 log_warning("Failed to send delayed message: %s", bus_error_message_or_strerror(&error, -r));
                 dbus_error_free(&error);
                 return r;
         }
 
-        /* Tell people about it */
-        send_prepare_for(manager, manager->delayed_what, false);
-
         return 1;
 }
diff --git a/src/login/logind.c b/src/login/logind.c
index 6776229..ed0b748 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -187,6 +187,8 @@ void manager_free(Manager *m) {
         strv_free(m->kill_only_users);
         strv_free(m->kill_exclude_users);
 
+        free(m->action_job);
+
         free(m->cgroup_path);
         free(m);
 }
diff --git a/src/login/logind.h b/src/login/logind.h
index 816635d..fe6ea0f 100644
--- a/src/login/logind.h
+++ b/src/login/logind.h
@@ -100,7 +100,9 @@ struct Manager {
 
         usec_t inhibit_delay_max;
 
-        int idle_action_fd;
+        char* action_job;
+
+        int idle_action_fd; /* the timer_fd */
         usec_t idle_action_usec;
         usec_t idle_action_not_before_usec;
         HandleAction idle_action;



More information about the systemd-commits mailing list