summaryrefslogtreecommitdiffstats
path: root/src/core/service.c
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2024-04-05 15:21:49 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2024-04-10 09:32:04 +0200
commit7072777163bef1877d65dce07e0914cf57c6ea38 (patch)
tree5873f6d7295b7d0b3bee417d645b0d891cca33da /src/core/service.c
parentpo: update Japanese translation (diff)
downloadsystemd-7072777163bef1877d65dce07e0914cf57c6ea38.tar.xz
systemd-7072777163bef1877d65dce07e0914cf57c6ea38.zip
core: Serialize both pid and pidfd
If we try to deserialize only a pidfd that points to a process that has been reaped, creating the pidref object will fail, which means that we'll try to create a pidref object from the serialized pid that comes next. If the pid has already been reused, this will succeed and we'll now have a pidref that points to a different process. Let's avoid this issue by serializing both the pidfd and the pid and creating the pidref object directly from both. This means we'll reuse the deserialized pidfd instead of opening a new one. We'll then immediately notice the pidfd is dead and do the appropriate follow up depending on the unit type.
Diffstat (limited to 'src/core/service.c')
-rw-r--r--src/core/service.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/core/service.c b/src/core/service.c
index 6d0281fcd7..f6800c3170 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -3184,7 +3184,7 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
} else if (streq(key, "main-pid")) {
PidRef pidref;
- if (deserialize_pidref(fds, value, &pidref) >= 0)
+ if (!pidref_is_set(&s->main_pid) && deserialize_pidref(fds, value, &pidref) >= 0)
(void) service_set_main_pidref(s, pidref);
} else if (streq(key, "main-pid-known")) {