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 6c86f09)
  • Loading branch information
vtjnash committed Jun 10, 2019
1 parent abcf8e5 commit c4ad8c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/unix/linux-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
*/
if (epoll_ctl(loop->backend_fd, op, w->fd, &e)) {
if (errno == EPERM) { /* fd is probably a file, which is always ready */
w->cb(loop, w, UV__EPOLLIN | UV__EPOLLOUT);
w->cb(loop, w, POLLIN | POLLOUT);
timeout = 0; /* fd is now likely closed and needs to return to the uv_run loop for cleanup */
} else if (errno != EEXIST) {
abort();
Expand Down
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 @@ -391,6 +392,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 @@ -463,8 +466,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 @@ -476,6 +483,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 @@ -529,7 +537,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 @@ -548,6 +556,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 c4ad8c2

Please sign in to comment.