From d70c66b24a69a67a17e6d216ab1d28b887588e2d Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Wed, 14 Jan 2026 03:59:36 -0800 Subject: [PATCH] Fix pid issue --- die-with-parent.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/die-with-parent.c b/die-with-parent.c index 150e63c..57d5740 100644 --- a/die-with-parent.c +++ b/die-with-parent.c @@ -116,7 +116,7 @@ int main(int argc, char *const *argv) { int signal_num = SIGHUP; bool no_search = false; bool had_error = false; - pid_t init_ppid = -1; + pid_t init_ppid = 0; int c; const char *old_posixly_correct = getenv("POSIXLY_CORRECT"); putenv("POSIXLY_CORRECT=1"); @@ -180,12 +180,14 @@ int main(int argc, char *const *argv) { return 1; } // we now check if the parent exited before this point - pid_t new_ppid = getppid(); - if (new_ppid != init_ppid) { - raise(signal_num); - // if we got here that means the signal in question was ignored which is - // probably what the user intended, so just go on with execing the new - // process + if (init_ppid > 0) { + pid_t new_ppid = getppid(); + if (new_ppid != init_ppid) { + raise(signal_num); + // if we got here that means the signal in question was ignored + // which is probably what the user intended, so just go on with + // execing the new process + } } const char *func; if (no_search) {