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) {