summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-18 14:56:08 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-18 14:56:08 +0000
commitcfb61e5962ecaebc457da0f7e9b6903f6ce7f0c1 (patch)
tree0172feac6879caac8bf8917a7ee7f2ee21497d2e
parent2fd7044e9a79df6b7f8248e8bae8d1850a211da1 (diff)
merge revision(s) 59975: [Backport #13916]
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/branches/ruby_2_3@62816 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog15
-rw-r--r--process.c8
-rw-r--r--test/ruby/test_process.rb10
-rw-r--r--version.h2
4 files changed, 32 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index bfd67f7362..0547c1ded5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+Sun Mar 18 23:55:23 2018 Eric Wong <normalperson@yhbt.net>
+
+ 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 freshlyfork'-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
+ [Bug #13916]
+
+ Thanks to Russell Davis for the bug report and test case.
+
Sun Mar 18 23:52:37 2018 Kazuki Tsujimoto <kazuki@callcc.net>
vm.c: fix `cfp consistency error' which occurs when raising exception
diff --git a/process.c b/process.c
index fd58103345..843e1dbbb0 100644
--- a/process.c
+++ b/process.c
@@ -3648,7 +3648,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;
@@ -3656,10 +3656,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 */
@@ -3672,14 +3674,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;
}
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index f46deb8720..3bab001654 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -2298,4 +2298,14 @@ EOS
end
end
end
+
+ def test_forked_child_handles_signal
+ skip "fork not supported" unless Process.respond_to?(:fork)
+ assert_normal_exit(<<-"end;", '[ruby-core:82883] [Bug #13916]')
+ require 'timeout'
+ pid = fork { sleep }
+ Process.kill(:TERM, pid)
+ assert_equal pid, Timeout.timeout(30) { Process.wait(pid) }
+ end;
+ end
end
diff --git a/version.h b/version.h
index 232a5b499a..b2b705136b 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.3.7"
#define RUBY_RELEASE_DATE "2018-03-18"
-#define RUBY_PATCHLEVEL 417
+#define RUBY_PATCHLEVEL 418
#define RUBY_RELEASE_YEAR 2018
#define RUBY_RELEASE_MONTH 3