summaryrefslogtreecommitdiff
path: root/process.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-20 18:47:14 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-20 18:47:14 +0000
commit5be3869221b83b7f3f08854cefdb59f279d74bde (patch)
treee55589178623f5c3a910285a58ddfc9ccb5ccdb4 /process.c
parent5da2f77b93e0abd17ad9bf3c4ba6d843b0e0a86d (diff)
process: block/unblock signals around fork
As with forking for execve(2) in `spawn', we must block signals to ensure they are handled correctly in a freshly `fork'-ed child. * process.c (retry_fork_ruby): block/unblock signals around fork (rb_fork_ruby): re-enable signals in forked child * test/ruby/test_process.rb (test_forked_child_signal): new test [ruby-core:82883] [Bug #13916] Thanks to Russell Davis for the bug report and test case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r--process.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/process.c b/process.c
index 300ba43f86..2d842176bd 100644
--- a/process.c
+++ b/process.c
@@ -3633,7 +3633,7 @@ rb_fork_async_signal_safe(int *status, int (*chfunc)(void*, char *, size_t), voi
}
static rb_pid_t
-retry_fork_ruby(int *status)
+retry_fork_ruby(int *status, struct child_handler_disabler_state *old)
{
rb_pid_t pid;
int try_gc = 1;
@@ -3641,10 +3641,12 @@ retry_fork_ruby(int *status)
while (1) {
prefork();
before_fork_ruby();
+ disable_child_handler_before_fork(old);
pid = fork();
if (pid == 0) /* fork succeed, child process */
return pid;
preserving_errno(after_fork_ruby());
+ preserving_errno(disable_child_handler_fork_parent(old));
if (0 < pid) /* fork succeed, parent process */
return pid;
/* fork failed */
@@ -3657,14 +3659,16 @@ rb_pid_t
rb_fork_ruby(int *status)
{
rb_pid_t pid;
+ struct child_handler_disabler_state old;
if (status) *status = 0;
- pid = retry_fork_ruby(status);
+ pid = retry_fork_ruby(status, &old);
if (pid < 0)
return pid;
if (!pid) {
after_fork_ruby();
+ disable_child_handler_fork_parent(&old); /* yes, bad name */
}
return pid;
}