Handle signal handler setup error properly in head process
This commit is contained in:
parent
d0feff88b1
commit
dfbf2767f2
1 changed files with 8 additions and 1 deletions
9
main.c
9
main.c
|
@ -83,7 +83,14 @@ int main(int argc, char* const* argv)
|
|||
pid_child = pid;
|
||||
if (sigaction(SIGTERM, &forward_signal_descriptor, NULL) == -1)
|
||||
{
|
||||
printf("Unable to setup signal handler in head\n");
|
||||
int err = errno;
|
||||
// Have to kill child here, otherwise that gets orphaned and runs anyway.
|
||||
// Use SIGKILL here because it might forward SIGTERM to its child and that
|
||||
// decides not to stop.
|
||||
kill(pid_child, SIGKILL);
|
||||
// Restore errno as it might've been overwritten by kill
|
||||
errno = err;
|
||||
err(errno, "Unable to set up signal handler in head process");
|
||||
}
|
||||
// parent waits for child then exits
|
||||
// Could be interrupt due to a signal. Retry in that case.
|
||||
|
|
Loading…
Reference in a new issue