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 [#3148](#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 109719d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions contrib/tester-progs/fork-tester.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ void child1()
int ppid = getppid();
if (ppid == 1) {
break;
} else {
// If systemd run with --user
const char *manager_pid_str = getenv("MANAGERPID");
int manager_pid = atoi(manager_pid_str);
if (ppid == manager_pid)
break;
}
if (i == 30) {
fprintf(stderr, "giving up on waiting our parent to die\n");
Expand Down

0 comments on commit 109719d

Please sign in to comment.