]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind: Add fallback for when the PIDFDs= property is not available
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 21 Mar 2024 14:48:54 +0000 (15:48 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 21 Mar 2024 15:17:15 +0000 (16:17 +0100)
logind is not zero-downtime restartable yet, specifically it's not yet
restarted in the Fedora spec, so we can end up in situations where we're
running newer logind with older pid1 which doesn't know about the PIDFDs=
property, so let's make sure we have a fallback in place for when that
happens.

src/login/logind-dbus.c
src/login/logind-dbus.h
src/login/logind-session.c

index c342522e3f82dd992618bb2ec10c6aa28d510c69..678e077d90e0bb673d7220c51c1135cd4395189f 100644 (file)
@@ -4230,6 +4230,7 @@ int manager_start_scope(
                 Manager *manager,
                 const char *scope,
                 const PidRef *pidref,
+                bool allow_pidfd,
                 const char *slice,
                 const char *description,
                 const char * const *requires,
@@ -4299,7 +4300,10 @@ int manager_start_scope(
         if (r < 0)
                 return r;
 
-        r = bus_append_scope_pidref(m, pidref);
+        if (allow_pidfd)
+                r = bus_append_scope_pidref(m, pidref);
+        else
+                r = sd_bus_message_append(m, "(sv)", "PIDs", "au", 1, (uint32_t) pidref->pid);
         if (r < 0)
                 return r;
 
@@ -4330,8 +4334,27 @@ int manager_start_scope(
                 return r;
 
         r = sd_bus_call(manager->bus, m, 0, error, &reply);
-        if (r < 0)
+        if (r < 0) {
+                /* If this failed with a property we couldn't write, this is quite likely because the server
+                 * doesn't support PIDFDs yet, let's try without. */
+                if (allow_pidfd &&
+                    sd_bus_error_has_names(error, SD_BUS_ERROR_UNKNOWN_PROPERTY, SD_BUS_ERROR_PROPERTY_READ_ONLY))
+                        return manager_start_scope(
+                                        manager,
+                                        scope,
+                                        pidref,
+                                        /* allow_pidfd = */ false,
+                                        slice,
+                                        description,
+                                        requires,
+                                        extra_after,
+                                        requires_mounts_for,
+                                        more_properties,
+                                        error,
+                                        ret_job);
+
                 return r;
+        }
 
         return strdup_job(reply, ret_job);
 }
index 5c864a9bc056a867b4e4a159208b724ebbec8828..8459d048b8ed882bb7165089fe29116b850021f9 100644 (file)
@@ -28,6 +28,7 @@ int manager_start_scope(
                 Manager *manager,
                 const char *scope,
                 const PidRef *pidref,
+                bool allow_pidfd,
                 const char *slice,
                 const char *description,
                 const char * const *requires,
index 2713215e10a47aa9b8ced28d22807cc50eb01ca8..4713aa05b55c8a6adf28bd6157a1824e1d2c04ec 100644 (file)
@@ -742,6 +742,7 @@ static int session_start_scope(Session *s, sd_bus_message *properties, sd_bus_er
                         s->manager,
                         scope,
                         &s->leader,
+                        /* allow_pidfd = */ true,
                         s->user->slice,
                         description,
                         /* These should have been pulled in explicitly in user_start(). Just to be sure. */