From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: spew@80x24.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B8F5E63381C for ; Sun, 5 Jul 2015 00:20:18 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH] test/ruby/test_process.rb: test for fd=3 usability in child Date: Sun, 5 Jul 2015 00:20:18 +0000 Message-Id: <1436055618-17689-1-git-send-email-e@80x24.org> List-Id: 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 :> --- test/ruby/test_process.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index a43dcf4..cda4cfc 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -2029,4 +2029,29 @@ 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 + assert_raises(ArgumentError) { IO.for_fd(3) } + 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 -- EW