From 2e87ef8b66e4b89fa39e10043a32f37e6ae35ae1 Mon Sep 17 00:00:00 2001 From: normal Date: Wed, 24 May 2017 00:34:12 +0000 Subject: [PATCH] rubyspec/core/io/popen_spec: avoid lingering "ruby -e sleep" process The ruby_cmd helper blindly escapes code blocks passed to it, causing "sleep" to be quoted in the command-line. This quoting results in IO.popen using a subshell (/bin/sh) to run the given string command instead of invoking the Ruby executable directly. Thus, IO.popen would only see the PID of the subshell via IO#pid, and merely sending SIGKILL to the subshell would not result in the child ("ruby -e sleep") being killed. This problem with lingering ruby processes was easier to reproduce on slow or heavily-loaded systems using low-scheduling priority (e.g. "chrt -i 0 make test-rubyspec") git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/rubyspec/core/io/popen_spec.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/rubyspec/core/io/popen_spec.rb b/spec/rubyspec/core/io/popen_spec.rb index 84a13f0a7f..f24e61032f 100644 --- a/spec/rubyspec/core/io/popen_spec.rb +++ b/spec/rubyspec/core/io/popen_spec.rb @@ -74,8 +74,12 @@ describe "IO.popen" do end it "does not throw an exception if child exited and has been waited for" do - @io = IO.popen(ruby_cmd('sleep')) - Process.kill "KILL", @io.pid + # Avoid the /bin/sh subshell using :options and :args to sleep. + # We don't want to kill only the subshell and leave "ruby -e sleep" + # running indefinitely + @io = IO.popen(ruby_cmd(nil, :options => '-e', :args => 'sleep')) + pid = @io.pid + Process.kill "KILL", pid @io.close platform_is_not :windows do $?.signaled?.should == true