Fix pid issue

This commit is contained in:
2026-01-14 03:59:36 -08:00
parent 0036be52a9
commit d70c66b24a

View File

@ -116,7 +116,7 @@ int main(int argc, char *const *argv) {
int signal_num = SIGHUP; int signal_num = SIGHUP;
bool no_search = false; bool no_search = false;
bool had_error = false; bool had_error = false;
pid_t init_ppid = -1; pid_t init_ppid = 0;
int c; int c;
const char *old_posixly_correct = getenv("POSIXLY_CORRECT"); const char *old_posixly_correct = getenv("POSIXLY_CORRECT");
putenv("POSIXLY_CORRECT=1"); putenv("POSIXLY_CORRECT=1");
@ -180,12 +180,14 @@ int main(int argc, char *const *argv) {
return 1; return 1;
} }
// we now check if the parent exited before this point // we now check if the parent exited before this point
if (init_ppid > 0) {
pid_t new_ppid = getppid(); pid_t new_ppid = getppid();
if (new_ppid != init_ppid) { if (new_ppid != init_ppid) {
raise(signal_num); raise(signal_num);
// if we got here that means the signal in question was ignored which is // if we got here that means the signal in question was ignored
// probably what the user intended, so just go on with execing the new // which is probably what the user intended, so just go on with
// process // execing the new process
}
} }
const char *func; const char *func;
if (no_search) { if (no_search) {