From 8ba3efed8669639457fc9b482d61d87e77f79b33 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Thu, 21 Mar 2024 15:48:54 +0100 Subject: [PATCH] logind: Add fallback for when the PIDFDs= property is not available 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 | 27 +++++++++++++++++++++++++-- src/login/logind-dbus.h | 1 + src/login/logind-session.c | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index c342522e3f8..678e077d90e 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -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); } diff --git a/src/login/logind-dbus.h b/src/login/logind-dbus.h index 5c864a9bc05..8459d048b8e 100644 --- a/src/login/logind-dbus.h +++ b/src/login/logind-dbus.h @@ -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, diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 2713215e10a..4713aa05b55 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -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. */ -- 2.47.3