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

ruby-changes:29834

From: nobu <ko1@a...>
Date: Wed, 10 Jul 2013 14:19:12 +0900 (JST)
Subject: [ruby-changes:29834] nobu:r41886 (trunk): process.c: kill threads in daemon process

nobu	2013-07-10 14:19:01 +0900 (Wed, 10 Jul 2013)

  New Revision: 41886

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41886

  Log:
    process.c: kill threads in daemon process
    
    * process.c (fork_daemon): kill the other threads all and abandon the
      kept mutexes.

  Modified files:
    trunk/ChangeLog
    trunk/process.c
    trunk/test/ruby/test_process.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41885)
+++ ChangeLog	(revision 41886)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jul 10 14:18:59 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* process.c (fork_daemon): kill the other threads all and abandon the
+	  kept mutexes.
+
+Wed Jul 10 14:14:44 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* process.c (fork_daemon): kill the other threads all and abandon the
+	  kept mutexes.
+
 Wed Jul 10 11:35:36 2013  NAKAMURA Usaku  <usa@r...>
 
 	* test/net/http/test_http.rb (TestNetHTTP_v1_2#test_get,
Index: process.c
===================================================================
--- process.c	(revision 41885)
+++ process.c	(revision 41886)
@@ -5742,7 +5742,7 @@ rb_daemon(int nochdir, int noclose) https://github.com/ruby/ruby/blob/trunk/process.c#L5742
 #define fork_daemon() \
     switch (rb_fork_ruby(NULL)) { \
       case -1: return -1; \
-      case 0:  break; \
+      case 0:  rb_thread_atfork(); break; \
       default: _exit(EXIT_SUCCESS); \
     }
 
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 41885)
+++ test/ruby/test_process.rb	(revision 41886)
@@ -1472,6 +1472,15 @@ class TestProcess < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1472
       assert_equal("ok?\n", data)
     end
 
+    def test_daemon_pid
+      cpid, dpid = IO.popen("-", "r+") do |f|
+        break f.pid, Integer(f.read) if f
+        Process.daemon(false, true)
+        puts $$
+      end
+      assert_not_equal(cpid, dpid)
+    end
+
     if File.directory?("/proc/self/task") && /netbsd[a-z]*[1-6]/ !~ RUBY_PLATFORM
       def test_daemon_no_threads
         pid, data = IO.popen("-", "r+") do |f|
@@ -1483,6 +1492,18 @@ class TestProcess < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1492
         assert_equal(2, data.size, bug4920)
         assert_not_include(data.map(&:to_i), pid)
       end
+    else
+      def test_daemon_no_threads
+        data = Timeout.timeout(3) do
+          IO.popen("-") do |f|
+            break f.readlines.map(&:chomp) if f
+            th = Thread.start {sleep 3}
+            Process.daemon(true, true)
+            puts Thread.list.size, th.status.inspect
+          end
+        end
+        assert_equal(["1", "false"], data)
+      end
     end
   end
 

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

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