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

ruby-changes:46748

From: normal <ko1@a...>
Date: Wed, 24 May 2017 09:34:25 +0900 (JST)
Subject: [ruby-changes:46748] normal:r58863 (trunk): rubyspec/core/io/popen_spec: avoid lingering "ruby -e sleep" process

normal	2017-05-24 09:34:12 +0900 (Wed, 24 May 2017)

  New Revision: 58863

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

  Log:
    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")

  Modified files:
    trunk/spec/rubyspec/core/io/popen_spec.rb
Index: spec/rubyspec/core/io/popen_spec.rb
===================================================================
--- spec/rubyspec/core/io/popen_spec.rb	(revision 58862)
+++ spec/rubyspec/core/io/popen_spec.rb	(revision 58863)
@@ -74,8 +74,12 @@ describe "IO.popen" do https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/core/io/popen_spec.rb#L74
   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

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

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