Blob Blame History Raw
From 10c5a4fec72a42369af812769802be974af3a012 Mon Sep 17 00:00:00 2001
From: Michal Sekletar <msekleta@redhat.com>
Date: Mon, 3 Mar 2014 16:07:39 +0100
Subject: [PATCH] logind: order all scopes after both systemd-logind.service
 and systemd-user-sessions.service

This way at shutdown we can be sure that the sessions go away before the
network.

Based-on: ba4c5d93b73ef7bba0ae0c6bf2b36a42360f7a34
---
 src/login/logind-dbus.c    | 17 ++++++++++++++---
 src/login/logind-session.c |  2 +-
 src/login/logind.h         |  2 +-
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 8de301e..a68e9b4 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -2545,10 +2545,11 @@ int manager_start_scope(
                 const char *slice,
                 const char *description,
                 const char *after,
+                const char *after2,
                 DBusError *error,
                 char **job) {
 
-        const char *timeout_stop_property = "TimeoutStopUSec", *send_sighup_property = "SendSIGHUP", *pids_property = "PIDs";
+        const char *timeout_stop_property = "TimeoutStopUSec", *send_sighup_property = "SendSIGHUP", *pids_property = "PIDs", *after_property = "After";
         _cleanup_dbus_message_unref_ DBusMessage *m = NULL, *reply = NULL;
         DBusMessageIter iter, sub, sub2, sub3, sub4;
         uint64_t timeout = 500 * USEC_PER_MSEC;
@@ -2603,8 +2604,6 @@ int manager_start_scope(
         }
 
         if (!isempty(after)) {
-                const char *after_property = "After";
-
                 if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) ||
                     !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &after_property) ||
                     !dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, "as", &sub3) ||
@@ -2616,6 +2615,18 @@ int manager_start_scope(
                         return log_oom();
         }
 
+        if (!isempty(after2)) {
+                if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) ||
+                    !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &after_property) ||
+                    !dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, "as", &sub3) ||
+                    !dbus_message_iter_open_container(&sub3, DBUS_TYPE_ARRAY, "s", &sub4) ||
+                    !dbus_message_iter_append_basic(&sub4, DBUS_TYPE_STRING, &after2) ||
+                    !dbus_message_iter_close_container(&sub3, &sub4) ||
+                    !dbus_message_iter_close_container(&sub2, &sub3) ||
+                    !dbus_message_iter_close_container(&sub, &sub2))
+                        return log_oom();
+        }
+
         /* cgroup empty notification is not available in containers
          * currently. To make this less problematic, let's shorten the
          * stop timeout for sessions, so that we don't wait
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index 78e6d74..2bac0a2 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -518,7 +518,7 @@ static int session_start_scope(Session *s) {
                 if (!scope)
                         return log_oom();
 
-                r = manager_start_scope(s->manager, scope, s->leader, s->user->slice, description, "systemd-logind.service", &error, &job);
+                r = manager_start_scope(s->manager, scope, s->leader, s->user->slice, description, "systemd-logind.service", "systemd-user-session.service", &error, &job);
                 if (r < 0) {
                         log_error("Failed to start session scope %s: %s %s",
                                   scope, bus_error(&error, r), error.name);
diff --git a/src/login/logind.h b/src/login/logind.h
index 0d2248f..540572f 100644
--- a/src/login/logind.h
+++ b/src/login/logind.h
@@ -184,7 +184,7 @@ int manager_send_changed(Manager *manager, const char *properties);
 
 int manager_dispatch_delayed(Manager *manager);
 
-int manager_start_scope(Manager *manager, const char *scope, pid_t pid, const char *slice, const char *description, const char *after, DBusError *error, char **job);
+int manager_start_scope(Manager *manager, const char *scope, pid_t pid, const char *slice, const char *description, const char *after, const char *after2, DBusError *error, char **job);
 int manager_start_unit(Manager *manager, const char *unit, DBusError *error, char **job);
 int manager_stop_unit(Manager *manager, const char *unit, DBusError *error, char **job);
 int manager_abandon_scope(Manager *manager, const char *scope, DBusError *error);