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 ad77730
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions contrib/tester-progs/fork-tester.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ void child1()
int ppid = getppid();
if (ppid == 1) {
break;
} else {
// If systemd run with --user
const char *manager_pid_str = getenv("MANAGERPID");
if (manager_pid_str) {
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 ad77730

Please sign in to comment.