Skip to content

Commit

Permalink
protect uv_spawn from signals (fix timholy/IProfile.jl#16)
Browse files Browse the repository at this point in the history
(cherry picked from commit dd01730)
  • Loading branch information
vtjnash committed Jul 23, 2021
1 parent a81432b commit 72fffe3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/unix/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <fcntl.h>
#include <poll.h>
#include <sched.h>
#include <signal.h>

#if defined(__APPLE__) && !TARGET_OS_IPHONE
# include <crt_externs.h>
Expand Down Expand Up @@ -394,6 +395,8 @@ int uv_spawn(uv_loop_t* loop,
int exec_errorno;
int i;
int status;
sigset_t sigset;
sigset_t sigoset;

if (options->cpumask != NULL) {
#if defined(__linux__) || defined(__FreeBSD__)
Expand Down Expand Up @@ -466,8 +469,12 @@ int uv_spawn(uv_loop_t* loop,

uv_signal_start(&loop->child_watcher, uv__chld, SIGCHLD);

sigfillset(&sigset);
sigprocmask(SIG_SETMASK, &sigset, &sigoset);

/* Acquire write lock to prevent opening new fds in worker threads */
uv_rwlock_wrlock(&loop->cloexec_lock);

pid = fork();

if (pid == -1) {
Expand All @@ -479,6 +486,7 @@ int uv_spawn(uv_loop_t* loop,
}

if (pid == 0) {
sigprocmask(SIG_SETMASK, &sigoset, NULL);
uv__process_child_init(options, stdio_count, pipes, signal_pipe[1]);
abort();
}
Expand Down Expand Up @@ -532,7 +540,7 @@ int uv_spawn(uv_loop_t* loop,

if (pipes != pipes_storage)
uv__free(pipes);

sigprocmask(SIG_SETMASK, &sigoset, NULL);
return exec_errorno;

error:
Expand All @@ -551,6 +559,8 @@ int uv_spawn(uv_loop_t* loop,
uv__free(pipes);
}

sigprocmask(SIG_SETMASK, &sigoset, NULL);

return err;
#endif
}
Expand Down

0 comments on commit 72fffe3

Please sign in to comment.