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 Jun 18, 2013
1 parent b093adc commit c45ec47
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/unix/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static void uv__process_child_init(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 @@ -278,6 +278,10 @@ int uv_spawn(uv_loop_t* loop,
UV_PROCESS_SETUID |
UV_PROCESS_WINDOWS_HIDE |
UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS)));

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

uv__handle_init(loop, (uv_handle_t*)process, UV_PROCESS);
QUEUE_INIT(&process->queue);
Expand Down Expand Up @@ -324,7 +328,7 @@ int uv_spawn(uv_loop_t* loop,
goto error;

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

pid = fork();

if (pid == -1) {
Expand All @@ -334,6 +338,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 @@ -364,6 +369,7 @@ int uv_spawn(uv_loop_t* loop,
uv__handle_start(process);

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

error:
Expand All @@ -374,6 +380,7 @@ int uv_spawn(uv_loop_t* loop,
close(pipes[i]);
}
free(pipes);
sigprocmask(SIG_SETMASK, &sigoset, NULL);

return -1;
}
Expand Down

0 comments on commit c45ec47

Please sign in to comment.