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 Mar 30, 2014
1 parent c263e4e commit 106c6fd
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/unix/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ static void uv__process_child_init(const uv_process_options_t* options,
_exit(127);
}


#include <signal.h>
int uv_spawn(uv_loop_t* loop,
uv_process_t* process,
const uv_process_options_t* options) {
Expand All @@ -304,7 +304,7 @@ int uv_spawn(uv_loop_t* loop,
int err;
int exec_errorno;
int i;

assert(options->file != NULL);
assert(!(options->flags & ~(UV_PROCESS_DETACHED |
UV_PROCESS_SETGID |
Expand Down Expand Up @@ -360,8 +360,13 @@ int uv_spawn(uv_loop_t* loop,

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

sigset_t sigset, sigoset;
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 @@ -373,6 +378,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 @@ -409,6 +415,7 @@ int uv_spawn(uv_loop_t* loop,
process->exit_cb = options->exit_cb;

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

error:
Expand All @@ -420,6 +427,9 @@ int uv_spawn(uv_loop_t* loop,
}
}

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

return err;
}

Expand Down

0 comments on commit 106c6fd

Please sign in to comment.