Skip to content

Commit 5810c25

Browse files
DaanDeMeyerkeszybz
authored andcommitted
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. (cherry picked from commit 8ba3efe)
1 parent b3fd8fa commit 5810c25

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/login/logind-dbus.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4126,6 +4126,7 @@ int manager_start_scope(
41264126
Manager *manager,
41274127
const char *scope,
41284128
const PidRef *pidref,
4129+
bool allow_pidfd,
41294130
const char *slice,
41304131
const char *description,
41314132
char **wants,
@@ -4191,7 +4192,10 @@ int manager_start_scope(
41914192
if (r < 0)
41924193
return r;
41934194

4194-
r = bus_append_scope_pidref(m, pidref);
4195+
if (allow_pidfd)
4196+
r = bus_append_scope_pidref(m, pidref);
4197+
else
4198+
r = sd_bus_message_append(m, "(sv)", "PIDs", "au", 1, (uint32_t) pidref->pid);
41954199
if (r < 0)
41964200
return r;
41974201

@@ -4222,8 +4226,27 @@ int manager_start_scope(
42224226
return r;
42234227

42244228
r = sd_bus_call(manager->bus, m, 0, error, &reply);
4225-
if (r < 0)
4229+
if (r < 0) {
4230+
/* If this failed with a property we couldn't write, this is quite likely because the server
4231+
* doesn't support PIDFDs yet, let's try without. */
4232+
if (allow_pidfd &&
4233+
sd_bus_error_has_names(error, SD_BUS_ERROR_UNKNOWN_PROPERTY, SD_BUS_ERROR_PROPERTY_READ_ONLY))
4234+
return manager_start_scope(
4235+
manager,
4236+
scope,
4237+
pidref,
4238+
/* allow_pidfd = */ false,
4239+
slice,
4240+
description,
4241+
wants,
4242+
after,
4243+
requires_mounts_for,
4244+
more_properties,
4245+
error,
4246+
job);
4247+
42264248
return r;
4249+
}
42274250

42284251
return strdup_job(reply, job);
42294252
}

src/login/logind-dbus.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,19 @@ int match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error
2424

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

27-
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);
27+
int manager_start_scope(
28+
Manager *manager,
29+
const char *scope,
30+
const PidRef *pidref,
31+
bool allow_pidfd,
32+
const char *slice,
33+
const char *description,
34+
char **wants,
35+
char **after,
36+
const char *requires_mounts_for,
37+
sd_bus_message *more_properties,
38+
sd_bus_error *error,
39+
char **job);
2840
int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
2941
int manager_stop_unit(Manager *manager, const char *unit, const char *job_mode, sd_bus_error *error, char **job);
3042
int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error);

src/login/logind-session.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ static int session_start_scope(Session *s, sd_bus_message *properties, sd_bus_er
686686
s->manager,
687687
scope,
688688
&s->leader,
689+
/* allow_pidfd = */ true,
689690
s->user->slice,
690691
description,
691692
/* These two have StopWhenUnneeded= set, hence add a dep towards them */

0 commit comments

Comments
 (0)