|
8 | 8 | #include "bfstd.h" |
9 | 9 | #include "diag.h" |
10 | 10 | #include "list.h" |
| 11 | +#include "sighook.h" |
11 | 12 |
|
12 | 13 | #include <errno.h> |
13 | 14 | #include <fcntl.h> |
@@ -535,7 +536,7 @@ static bool bfs_use_posix_spawn(const struct bfs_resolver *res, const struct bfs |
535 | 536 |
|
536 | 537 | /** Actually exec() the new process. */ |
537 | 538 | _noreturn |
538 | | -static void bfs_spawn_exec(struct bfs_resolver *res, const struct bfs_spawn *ctx, char **argv, char **envp, int pipefd[2]) { |
| 539 | +static void bfs_spawn_exec(struct bfs_resolver *res, const struct bfs_spawn *ctx, char **argv, char **envp, const sigset_t *mask, int pipefd[2]) { |
539 | 540 | xclose(pipefd[0]); |
540 | 541 |
|
541 | 542 | for_slist (const struct bfs_spawn_action, action, ctx) { |
@@ -596,6 +597,18 @@ static void bfs_spawn_exec(struct bfs_resolver *res, const struct bfs_spawn *ctx |
596 | 597 | goto fail; |
597 | 598 | } |
598 | 599 |
|
| 600 | + // Reset signal handlers to their original values before we unblock |
| 601 | + // signals, so that handlers don't run in both the parent and the child |
| 602 | + if (sigreset() != 0) { |
| 603 | + goto fail; |
| 604 | + } |
| 605 | + |
| 606 | + // Restore the original signal mask for the child process |
| 607 | + errno = pthread_sigmask(SIG_SETMASK, mask, NULL); |
| 608 | + if (errno != 0) { |
| 609 | + goto fail; |
| 610 | + } |
| 611 | + |
599 | 612 | execve(res->exe, argv, envp); |
600 | 613 |
|
601 | 614 | fail:; |
@@ -635,7 +648,7 @@ static pid_t bfs_fork_spawn(struct bfs_resolver *res, const struct bfs_spawn *ct |
635 | 648 | #endif |
636 | 649 | if (pid == 0) { |
637 | 650 | // Child |
638 | | - bfs_spawn_exec(res, ctx, argv, envp, pipefd); |
| 651 | + bfs_spawn_exec(res, ctx, argv, envp, &old_mask, pipefd); |
639 | 652 | } |
640 | 653 |
|
641 | 654 | // Restore the original signal mask |
|
0 commit comments