aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-05 00:40:14 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-05 00:40:14 +0000
commit3ba1ea76b1a813e7718709f2c0ccbc75cd882923 (patch)
treee70c4283ac35cc5fe7b07de8c996399d089d210a
parent63b7a92dd2eb032bd68c05fede8d16864f4db6e9 (diff)
downloadruby-3ba1ea76b1a813e7718709f2c0ccbc75cd882923.tar.gz
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 :> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51146 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--test/ruby/test_process.rb24
2 files changed, 28 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 9f37a2cf36..977fb57b65 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sun Jul 5 09:31:40 2015 Eric Wong <e@80x24.org>
+
+ * test/ruby/test_process.rb: test for fd=3 usability in child
+
Sat Jul 4 19:43:31 2015 SHIBATA Hiroshi <hsbt@ruby-lang.org>
* Add test case for empty array and first method with args.
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index a43dcf475c..cb9440c836 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -2029,4 +2029,28 @@ EOS
}
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