[前][次][番号順一覧][スレッド一覧]

ruby-changes:50654

From: usa <ko1@a...>
Date: Sun, 18 Mar 2018 23:56:13 +0900 (JST)
Subject: [ruby-changes:50654] usa:r62816 (ruby_2_3): merge revision(s) 59975: [Backport #13916]

usa	2018-03-18 23:56:08 +0900 (Sun, 18 Mar 2018)

  New Revision: 62816

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62816

  Log:
    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.

  Modified directories:
    branches/ruby_2_3/
  Modified files:
    branches/ruby_2_3/ChangeLog
    branches/ruby_2_3/process.c
    branches/ruby_2_3/test/ruby/test_process.rb
    branches/ruby_2_3/version.h
Index: ruby_2_3/test/ruby/test_process.rb
===================================================================
--- ruby_2_3/test/ruby/test_process.rb	(revision 62815)
+++ ruby_2_3/test/ruby/test_process.rb	(revision 62816)
@@ -2298,4 +2298,14 @@ EOS https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_process.rb#L2298
       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
Index: ruby_2_3/process.c
===================================================================
--- ruby_2_3/process.c	(revision 62815)
+++ ruby_2_3/process.c	(revision 62816)
@@ -3648,7 +3648,7 @@ rb_fork_async_signal_safe(int *status, i https://github.com/ruby/ruby/blob/trunk/ruby_2_3/process.c#L3648
 }
 
 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) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/process.c#L3656
     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 https://github.com/ruby/ruby/blob/trunk/ruby_2_3/process.c#L3674
 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;
 }
Index: ruby_2_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 62815)
+++ ruby_2_3/version.h	(revision 62816)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #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
Index: ruby_2_3/ChangeLog
===================================================================
--- ruby_2_3/ChangeLog	(revision 62815)
+++ ruby_2_3/ChangeLog	(revision 62816)
@@ -1,3 +1,18 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1
+Sun Mar 18 23:55:23 2018  Eric Wong  <normalperson@y...>
+
+	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@c...>
 
 	vm.c: fix `cfp consistency error' which occurs when raising exception
Index: ruby_2_3
===================================================================
--- ruby_2_3	(revision 62815)
+++ ruby_2_3	(revision 62816)

Property changes on: ruby_2_3
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r59975

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]