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

ruby-changes:52191

From: normal <ko1@a...>
Date: Fri, 17 Aug 2018 08:56:16 +0900 (JST)
Subject: [ruby-changes:52191] normal:r64399 (trunk): process.c: defaults to close_others false

normal	2018-08-17 08:56:08 +0900 (Fri, 17 Aug 2018)

  New Revision: 64399

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

  Log:
    process.c: defaults to close_others false
    
    Arbitrarily closing file descriptors on exec breaks use cases
    where a Ruby process sets up a descriptor for non-Ruby children
    to use.  For example, the "rake foo" target may spawn any number
    of subprocesses (Ruby or not) which depends on parsing the "FOO"
    environment variable for out_fd:99 and writing to foo.out
    
        FOO=out_fd:99 rake foo 99>>foo.out
    
    Unfortunately, this introduced one incompatibility in
    test/lib/test/unit.rb and it now requires explicitly setting
    IO#close_on_exec=true
    
    [ruby-core:88007] [Misc #14907]

  Modified files:
    trunk/process.c
    trunk/test/lib/test/unit.rb
    trunk/test/ruby/test_process.rb
Index: process.c
===================================================================
--- process.c	(revision 64398)
+++ process.c	(revision 64399)
@@ -3496,7 +3496,7 @@ rb_execarg_run_options(const struct rb_e https://github.com/ruby/ruby/blob/trunk/process.c#L3496
     }
 
 #ifdef HAVE_WORKING_FORK
-    if (!eargp->close_others_given || eargp->close_others_do) {
+    if (eargp->close_others_do) {
         rb_close_before_exec(3, eargp->close_others_maxhint, eargp->redirect_fds); /* async-signal-safe */
     }
 #endif
@@ -4568,7 +4568,7 @@ rb_f_system(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/process.c#L4568
  *          integer : the file descriptor of specified the integer
  *          io      : the file descriptor specified as io.fileno
  *      file descriptor inheritance: close non-redirected non-standard fds (3, 4, 5, ...) or not
- *        :close_others => true  : don't inherit
+ *        :close_others => false  : inherit
  *      current directory:
  *        :chdir => str
  *
@@ -4727,7 +4727,7 @@ rb_f_system(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/process.c#L4727
  *    pid = spawn(command, :close_others=>true)  # close 3,4,5,... (default)
  *    pid = spawn(command, :close_others=>false) # don't close 3,4,5,...
  *
- *  :close_others is true by default for spawn and IO.popen.
+ *  :close_others is false by default for spawn and IO.popen.
  *
  *  Note that fds which close-on-exec flag is already set are closed
  *  regardless of :close_others option.
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 64398)
+++ test/ruby/test_process.rb	(revision 64399)
@@ -1009,6 +1009,15 @@ class TestProcess < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1009
     }
   end
 
+  def test_close_others_default_false
+    IO.pipe do |r,w|
+      w.close_on_exec = false
+      src = "IO.new(#{w.fileno}).puts(:hi)"
+      assert_equal true, system(*%W(#{RUBY} --disable=gems -e #{src}))
+      assert_equal "hi\n", r.gets
+    end
+  end
+
   def test_execopts_redirect_self
     begin
       with_pipe {|r, w|
Index: test/lib/test/unit.rb
===================================================================
--- test/lib/test/unit.rb	(revision 64398)
+++ test/lib/test/unit.rb	(revision 64399)
@@ -145,6 +145,8 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit.rb#L145
             r.close if r
             nil
           else
+            r.close_on_exec = true
+            w.close_on_exec = true
             @jobserver = [r, w]
             options[:parallel] ||= 1
           end

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

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