about summary refs log tree commit homepage
path: root/lib/yahns/server_mp.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_mp.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_mp.rb')
-rw-r--r--lib/yahns/server_mp.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/yahns/server_mp.rb b/lib/yahns/server_mp.rb
index 1e2f1c8..115f94a 100644
--- a/lib/yahns/server_mp.rb
+++ b/lib/yahns/server_mp.rb
@@ -164,4 +164,25 @@ module Yahns::ServerMP # :nodoc:
     end
     alive
   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')
+      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