diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-02-09 07:03:02 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-02-09 07:03:02 +0000 |
commit | 7d740e5825e05030b5978ed296fd0b801666b405 (patch) | |
tree | 93da2eacbdf50c7664d7e5de671a2ce2ee271254 | |
parent | e427fb773837953c01ebe8dfaf8f8679c7895fc2 (diff) | |
download | cmogstored-7d740e5825e05030b5978ed296fd0b801666b405.tar.gz |
FD inheritance from exec() must be done explicitly in Ruby 2.0
-rw-r--r-- | test/inherit.rb | 13 |
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 |