Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
protect uv_spawn from signals (fix timholy/IProfile.jl#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Jul 18, 2015
1 parent d7eaae2 commit b2fe079
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/unix/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
#include <signal.h>

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

assert(options->file != NULL);
assert(!(options->flags & ~(UV_PROCESS_DETACHED |
Expand Down Expand Up @@ -365,8 +368,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 @@ -378,6 +385,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 @@ -419,6 +427,7 @@ int uv_spawn(uv_loop_t* loop,
process->exit_cb = options->exit_cb;

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

error:
Expand All @@ -433,6 +442,9 @@ int uv_spawn(uv_loop_t* loop,
uv__free(pipes);
}

free(pipes);
sigprocmask(SIG_SETMASK, &sigoset, NULL);

return err;
}

Expand Down

0 comments on commit b2fe079

Please sign in to comment.