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

ruby-changes:37724

From: nobu <ko1@a...>
Date: Mon, 2 Mar 2015 15:44:27 +0900 (JST)
Subject: [ruby-changes:37724] nobu:r49805 (trunk): envutil.rb: signal list to invoke_ruby

nobu	2015-03-02 15:44:22 +0900 (Mon, 02 Mar 2015)

  New Revision: 49805

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

  Log:
    envutil.rb: signal list to invoke_ruby
    
    * test/lib/envutil.rb (invoke_ruby): allow `signal` optional
      keyword argument to be a list of signals to be sent to the
      target process.

  Modified files:
    trunk/test/lib/envutil.rb
Index: test/lib/envutil.rb
===================================================================
--- test/lib/envutil.rb	(revision 49804)
+++ test/lib/envutil.rb	(revision 49805)
@@ -30,10 +30,13 @@ module EnvUtil https://github.com/ruby/ruby/blob/trunk/test/lib/envutil.rb#L30
 
   LANG_ENVS = %w"LANG LC_ALL LC_CTYPE"
 
+  DEFAULT_SIGNALS = Signal.list
+  DEFAULT_SIGNALS.delete("TERM") if /mswin|mingw/ =~ RUBY_PLATFORM
+
   def invoke_ruby(args, stdin_data = "", capture_stdout = false, capture_stderr = false,
                   encoding: nil, timeout: 10, reprieve: 1,
                   stdout_filter: nil, stderr_filter: nil,
-                  signal: (/mswin|mingw/ =~ RUBY_PLATFORM ? :KILL : :TERM),
+                  signal: :TERM,
                   rubybin: EnvUtil.rubybin,
                   **opt)
     in_c, in_p = IO.pipe
@@ -68,25 +71,34 @@ module EnvUtil https://github.com/ruby/ruby/blob/trunk/test/lib/envutil.rb#L71
         stdout = th_stdout.value if capture_stdout
         stderr = th_stderr.value if capture_stderr && capture_stderr != :merge_to_stdout
       else
+        signals = Array(signal).select do |sig|
+          DEFAULT_SIGNALS[sig.to_s] or
+            DEFAULT_SIGNALS[Signal.signame(sig)]
+        end
+        signals |= [:KILL]
         case pgroup = opt[:pgroup]
         when 0, true
           pgroup = -pid
         when nil, false
           pgroup = pid
         end
-        begin
-          Process.kill signal, pgroup
-          Timeout.timeout((reprieve unless signal == :KILL)) do
+        while signal = signals.shift
+          begin
+            Process.kill signal, pgroup
+          rescue Errno::Invalid
+            next
+          rescue Errno::ESRCH
+            break
+          end
+          if signals.empty? or !reprieve
             Process.wait(pid)
+          else
+            begin
+              Timeout.timeout(reprieve) {Process.wait(pid)}
+            rescue Timeout::Error
+            end
           end
-        rescue Errno::ESRCH
-          break
-        rescue Timeout::Error
-          raise if signal == :KILL
-          signal = :KILL
-        else
-          break
-        end while true
+        end
         bt = caller_locations
         raise Timeout::Error, "execution of #{bt.shift.label} expired", bt.map(&:to_s)
       end

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

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