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

ruby-changes:39065

From: normal <ko1@a...>
Date: Sun, 5 Jul 2015 09:40:36 +0900 (JST)
Subject: [ruby-changes:39065] normal:r51146 (trunk): test/ruby/test_process.rb: test for fd=3 usability in child

normal	2015-07-05 09:40:14 +0900 (Sun, 05 Jul 2015)

  New Revision: 51146

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

  Log:
    test/ruby/test_process.rb: test for fd=3 usability in child
    
    Ensure we can redirect anything to fd=3 in a child process.  This
    test exists because fd=3 is a commonly reserved FD for a timer
    thread pipe in the parent Ruby VM, but fd=3 is the first FD used by
    the sd_listen_fds function for systemd.
    
    This means there is a possibility for a bug to slip in where the
    redirect to fd=3 fails to work.  This test should ensure the
    continued viability of systemd replacements in Ruby :>

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_process.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51145)
+++ ChangeLog	(revision 51146)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jul  5 09:31:40 2015  Eric Wong  <e@8...>
+
+	* test/ruby/test_process.rb: test for fd=3 usability in child
+
 Sat Jul  4 19:43:31 2015  SHIBATA Hiroshi  <hsbt@r...>
 
 	* Add test case for empty array and first method with args.
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 51145)
+++ test/ruby/test_process.rb	(revision 51146)
@@ -2029,4 +2029,28 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L2029
     }
     assert_equal(th, x)
   end if defined?(fork)
+
+  def test_exec_fd_3_redirect
+    # ensure we can redirect anything to fd=3 in a child process.
+    # fd=3 is a commonly reserved FD for the timer thread pipe in the
+    # parent, but fd=3 is the first FD used by the sd_listen_fds function
+    # for systemd
+    assert_separately(['-', RUBY], <<-INPUT, timeout: 60)
+      ruby = ARGV.shift
+      begin
+        a = IO.pipe
+        b = IO.pipe
+        pid = fork do
+          exec ruby, '-e', 'print IO.for_fd(3).read(1)', 3 => a[0], 1 => b[1]
+        end
+        b[1].close
+        a[0].close
+        a[1].write('.')
+        assert_equal ".", b[0].read(1)
+      ensure
+        a.each(&:close) if a
+        b.each(&:close) if b
+      end
+    INPUT
+  end if defined?(fork)
 end

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

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