Handle EINTR error code for wait and waitpid

This commit is contained in:
madmaurice 2021-01-15 20:22:22 +01:00
parent 12e4cd391a
commit 48445a573b

7
main.c
View file

@ -104,9 +104,11 @@ int main(int argc, const char** argv)
printf("Unable to setup signal handler in head\n");
}
// parent waits for child then exits
// Could be interrupt due to a signal. Retry in that case.
int status;
if (waitpid(pid, &status, 0) == -1)
while (waitpid(pid, &status, 0) == -1)
{
if(errno == EINTR) continue; // On EINTR retry.
err = errno;
printf("Failed to wait (%d)\n", err);
return err;
@ -147,10 +149,11 @@ int main(int argc, const char** argv)
return 1;
}
// wait could be interrupt due to a signal. In that case just call wait again.
do {
exited_child = wait(&child_status);
err = errno;
} while (exited_child != first_child && exited_child != -1);
} while (!(exited_child == first_child || (exited_child == -1 && err != EINTR)));
if (exited_child == -1)
{