ruby-changes:19390
From: kosaki <ko1@a...>
Date: Wed, 4 May 2011 20:29:31 +0900 (JST)
Subject: [ruby-changes:19390] Ruby:r31430 (trunk): * io.c (Init_IO): Added File::CLOEXEC constant. [Feature #1291]
kosaki 2011-05-04 20:29:24 +0900 (Wed, 04 May 2011) New Revision: 31430 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31430 Log: * io.c (Init_IO): Added File::CLOEXEC constant. [ruby-core:22893] [Feature #1291] * test/ruby/test_io.rb (TestIO#test_o_cloexec): test for File::CLOEXEC. Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 31429) +++ ChangeLog (revision 31430) @@ -1,3 +1,9 @@ +Wed May 4 20:22:12 2011 KOSAKI Motohiro <kosaki.motohiro@g...> + + * io.c (Init_IO): Added File::CLOEXEC constant. + [ruby-core:22893] [Feature #1291] + * test/ruby/test_io.rb (TestIO#test_o_cloexec): test for File::CLOEXEC. + Wed May 4 19:00:59 2011 KOSAKI Motohiro <kosaki.motohiro@g...> * thread.c (rb_wait_for_single_fd): Fix wrong return value. Index: io.c =================================================================== --- io.c (revision 31429) +++ io.c (revision 31430) @@ -10576,6 +10576,10 @@ /* Try to minimize cache effects of the I/O to and from this file. */ rb_file_const("DIRECT", INT2FIX(O_DIRECT)); #endif +#ifdef O_CLOEXEC + /* enable close-on-exec flag */ + rb_file_const("CLOEXEC", INT2FIX(O_CLOEXEC)); /* Linux, POSIX-2008. */ +#endif sym_mode = ID2SYM(rb_intern("mode")); sym_perm = ID2SYM(rb_intern("perm")); Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 31429) +++ test/ruby/test_io.rb (revision 31430) @@ -1238,6 +1238,37 @@ end end + def test_O_CLOEXEC + if !defined? File::CLOEXEC + return + end + + mkcdtmpdir do + 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?) + + 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" + end + End + assert_equal("#{normal_file.fileno}\nnofile\n", f.read) + } + end + end + def test_close_security_error with_pipe do |r, w| assert_raise(SecurityError) do -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/