diff --git a/ChangeLog b/ChangeLog index 16f7bce67f..ffd8998aa2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu May 5 23:08:32 2011 KOSAKI Motohiro + + * test/ruby/test_io.rb (TestIO#test_O_CLOEXEC): fix false positive + detection. + Thu May 5 22:23:34 2011 KOSAKI Motohiro * thread_pthread.c (native_mutex_reinitialize_atfork): removed diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 5a55722115..07308a07ce 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1244,28 +1244,48 @@ class TestIO < Test::Unit::TestCase end mkcdtmpdir do - normal_file = Tempfile.new("normal_file"); - assert_equal(false, normal_file.close_on_exec?) + ary = [] + begin + 10.times { + ary.concat IO.pipe + } - cloexec_file = Tempfile.new("cloexec_file", :mode => File::CLOEXEC); - assert_equal(true, cloexec_file.close_on_exec?) + normal_file = Tempfile.new("normal_file"); + assert_equal(false, normal_file.close_on_exec?) + cloexec_file = Tempfile.new("cloexec_file", :mode => File::CLOEXEC); + assert_equal(true, cloexec_file.close_on_exec?) + arg, argw = IO.pipe + argw.puts normal_file.fileno + argw.puts cloexec_file.fileno + argw.flush + ret, retw = IO.pipe - argfile = Tempfile.new("argfile"); - - argfile.puts normal_file.fileno - argfile.puts cloexec_file.fileno - argfile.flush - - ruby('-e', <<-'End', argfile.path) { |f| - begin - puts IO.for_fd(ARGF.gets.to_i).fileno - puts IO.for_fd(ARGF.gets.to_i).fileno - rescue - puts "nofile" + while (e = ary.shift) != nil + e.close end - End - assert_equal("#{normal_file.fileno}\nnofile\n", f.read) - } + + spawn("ruby", "-e", <<-'End', :close_others=>false, :in=>arg, :out=>retw) + begin + puts IO.for_fd(gets.to_i).fileno + puts IO.for_fd(gets.to_i).fileno + rescue + puts "nofile" + ensure + exit + end + End + retw.close + Process.wait + assert_equal("#{normal_file.fileno}\nnofile\n", ret.read) + ensure + while (e = ary.shift) != nil + e.close + end + arg.close unless arg.closed? + argw.close unless argw.closed? + ret.close unless ret.closed? + retw.close unless retw.closed? + end end end