Skip to content

Commit

Permalink
[fork-tester.c] Get PPID from env MANAGERPID when systemd run with --…
Browse files Browse the repository at this point in the history
…user

Fix [cilium#3148](cilium#3148)
On certain distributions, `systemd` run with the flag `--user`. This
means that the manager PID is not 1 but one of it's child process.
To fix this, we call the environment variable `MANAGERPID` set by systemd
that expose this PID

Signed-off-by: Tristan d'Audibert <[email protected]>
  • Loading branch information
ScriptSathi committed Nov 21, 2024
1 parent cc9850a commit 6c0b4b3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion contrib/tester-progs/fork-tester.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@ void child1()
perror("fork");
exit(1);
} else if (pid == 0) {
int manager_pid = 1; // systemd init PID
for (int i = 0;; i++) {
int ppid = getppid();
if (ppid == 1) {
if (ppid == manager_pid) {
break;
} else {
// If systemd run with --user
const char *manager_pid_str = getenv("MANAGERPID");
if (manager_pid_str) {
manager_pid = atoi(manager_pid_str);
if (ppid == manager_pid)
break;
manager_pid = 1;
}
}
if (i == 30) {
fprintf(stderr, "giving up on waiting our parent to die\n");
Expand Down

0 comments on commit 6c0b4b3

Please sign in to comment.