Skip to content

Commit

Permalink
logind: Add fallback for when the PIDFDs= property is not available
Browse files Browse the repository at this point in the history
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.

(cherry picked from commit 8ba3efe)
  • Loading branch information
DaanDeMeyer authored and keszybz committed May 9, 2024
1 parent b3fd8fa commit 5810c25
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
27 changes: 25 additions & 2 deletions src/login/logind-dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -4126,6 +4126,7 @@ int manager_start_scope(
Manager *manager,
const char *scope,
const PidRef *pidref,
bool allow_pidfd,
const char *slice,
const char *description,
char **wants,
Expand Down Expand Up @@ -4191,7 +4192,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;

Expand Down Expand Up @@ -4222,8 +4226,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,
wants,
after,
requires_mounts_for,
more_properties,
error,
job);

return r;
}

return strdup_job(reply, job);
}
Expand Down
14 changes: 13 additions & 1 deletion src/login/logind-dbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@ int match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error

int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_;

int manager_start_scope(Manager *manager, const char *scope, const PidRef *pidref, const char *slice, const char *description, char **wants, char **after, const char *requires_mounts_for, sd_bus_message *more_properties, sd_bus_error *error, char **job);
int manager_start_scope(
Manager *manager,
const char *scope,
const PidRef *pidref,
bool allow_pidfd,
const char *slice,
const char *description,
char **wants,
char **after,
const char *requires_mounts_for,
sd_bus_message *more_properties,
sd_bus_error *error,
char **job);
int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
int manager_stop_unit(Manager *manager, const char *unit, const char *job_mode, sd_bus_error *error, char **job);
int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error);
Expand Down
1 change: 1 addition & 0 deletions src/login/logind-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,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 two have StopWhenUnneeded= set, hence add a dep towards them */
Expand Down

0 comments on commit 5810c25

Please sign in to comment.