about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-02-09 07:03:02 +0000
committerEric Wong <normalperson@yhbt.net>2013-02-09 07:03:02 +0000
commit7d740e5825e05030b5978ed296fd0b801666b405 (patch)
tree93da2eacbdf50c7664d7e5de671a2ce2ee271254
parente427fb773837953c01ebe8dfaf8f8679c7895fc2 (diff)
downloadcmogstored-7d740e5825e05030b5978ed296fd0b801666b405.tar.gz
FD inheritance from exec() must be done explicitly in Ruby 2.0
-rw-r--r--test/inherit.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/test/inherit.rb b/test/inherit.rb
index d9da78d..07efd3c 100644
--- a/test/inherit.rb
+++ b/test/inherit.rb
@@ -14,6 +14,8 @@ class TestInherit < Test::Unit::TestCase
     @to_close << @srv
     @port = @srv.addr[1]
     @err = Tempfile.new("stderr")
+    @pid = nil
+    @exec_fds = {}
   end
 
   # Ruby 1.8 did not have the close_on_exec= method, but it
@@ -21,7 +23,16 @@ class TestInherit < Test::Unit::TestCase
   # 2.0.0 will be the first release with close_on_exec=true
   # by default, but 1.9 already added the close_on_exec= method
   def maybe_cloexec(io, val)
-     io.close_on_exec = val if io.respond_to?(:close_on_exec=)
+    if io.respond_to?(:close_on_exec=)
+      io.close_on_exec = val
+      @exec_fds[io.fileno] = io
+    end
+  end
+
+  # FD inheritance is explicit in Ruby 2.0.0
+  def exec(*cmd)
+    cmd << @exec_fds if @exec_fds.size > 0
+    Process.exec(*cmd)
   end
 
   def teardown