about summary refs log tree commit homepage
path: root/lib/yahns/server.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-11-02 19:40:46 +0000
committerEric Wong <normalperson@yhbt.net>2013-11-02 21:21:27 +0000
commit1b31f96631af819efc6c779d9e14b53bb7313730 (patch)
tree96d992289d20fa68cf620fb6e81b858181f845f7 /lib/yahns/server.rb
parent38d6b9e49eed43256f610afcf4389ba7d85054e0 (diff)
downloadyahns-1b31f96631af819efc6c779d9e14b53bb7313730.tar.gz
We must not reap processes we did not spawn if we're not using a
master/worker configuration.  This may break applications which
depend on waitpid themselves.  However we still trap SIGCHLD
currently.  In the future, we could switch our notification
model mode to be compatible with apps which depend on SIGCHLD or
might indiscriminately on children (which might prevent us from
knowing about SIGCHLD).
Diffstat (limited to 'lib/yahns/server.rb')
-rw-r--r--lib/yahns/server.rb32
1 files changed, 10 insertions, 22 deletions
diff --git a/lib/yahns/server.rb b/lib/yahns/server.rb
index 898be2c..9eb5378 100644
--- a/lib/yahns/server.rb
+++ b/lib/yahns/server.rb
@@ -412,6 +412,15 @@ class Yahns::Server # :nodoc:
     end
   end
 
+  def reap_reexec
+    @reexec_pid > 0 or return
+    wpid, status = Process.waitpid2(@reexec_pid, Process::WNOHANG)
+    wpid or return
+    @logger.error "reaped #{status.inspect} exec()-ed"
+    @reexec_pid = 0
+    self.pid = @pid.chomp('.oldbin') if @pid
+  end
+
   def sp_sig_handle(alive)
     @sev.kgio_wait_readable(alive ? nil : 0.01)
     @sev.yahns_step
@@ -419,7 +428,7 @@ class Yahns::Server # :nodoc:
     when :QUIT, :TERM, :INT
       return quit_enter(alive)
     when :CHLD
-      reap_all
+      reap_reexec
     when :USR1
       usr1_reopen('')
     when :USR2
@@ -456,25 +465,4 @@ class Yahns::Server # :nodoc:
   ensure
     quit_finish
   end
-
-  # reaps all unreaped workers/reexec processes
-  def reap_all
-    begin
-      wpid, status = Process.waitpid2(-1, Process::WNOHANG)
-      wpid or return
-      if @reexec_pid == wpid
-        @logger.error "reaped #{status.inspect} exec()-ed"
-        @reexec_pid = 0
-        self.pid = @pid.chomp('.oldbin') if @pid
-        proc_name('master') if @worker_processes
-      else
-        worker = @workers.delete(wpid)
-        desc = worker ? "worker=#{worker.nr}" : "(unknown)"
-        m = "reaped #{status.inspect} #{desc}"
-        status.success? ? @logger.info(m) : @logger.error(m)
-      end
-    rescue Errno::ECHILD
-      return
-    end while true
-  end
 end