I ran into this problem a few hours ago.
Even though I have fixed it, I simply don't understand why this happens.
signal(SIGHUP, sighupHandler);
.
.
.
// sync with child by getting a char written by child
fgetc(pipe_in);
close(pipe_in);
int status;
if(waitpid(initProcessPid, &status, 0) == -1){
printf("debug: errno is %d\n", errno);
printf("failed to wait for init process to end\n");
}
Every time a SIGHUP happens during the waitpid() block, waitpid() returns -1 with errno 5.
Although a EINTR should be in errno this case as pointed out by alk, EINTR is 4, not 5.
After a few hours gathering ideas from gdb, since I'm not actually doing anything on SIGHUP currently, I changed my code to:
signal(SIGHUP, SIG_IGN);
Then it works properly, SIGHUP no longer breaks the waitpid() block.
I was working on a linux container that aims to be single file and static. https://github.com/Kethen/minicontainer