about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/yahns/config.rb14
-rw-r--r--lib/yahns/server.rb8
-rw-r--r--lib/yahns/server_mp.rb8
3 files changed, 14 insertions, 16 deletions
diff --git a/lib/yahns/config.rb b/lib/yahns/config.rb
index 9a63803..873722d 100644
--- a/lib/yahns/config.rb
+++ b/lib/yahns/config.rb
@@ -88,13 +88,11 @@ class Yahns::Config # :nodoc:
     end
   end
 
-  # atfork_prepare, atfork_parent, atfork_child
-  %w(prepare parent child).each do |x|
-    fn = "atfork_#{x}"
+  %w(atfork_prepare atfork_parent atfork_child).each do |fn|
     eval(
     %Q(def #{fn}(*args, &blk);) <<
     %Q(  _check_in_block(:worker_processes, :#{fn});) <<
-    %Q(  _add_hook("worker_", :#{fn}, block_given? ? blk : args[0]);) <<
+    %Q(  _add_hook(:#{fn}, block_given? ? blk : args[0]);) <<
     %Q(end)
     )
   end
@@ -104,7 +102,7 @@ class Yahns::Config # :nodoc:
     @set[var] = (block_given? ? blk : args[0])
   end
 
-  def _add_hook(pfx, var, my_proc)
+  def _add_hook(var, my_proc)
     case my_proc
     when Proc
       my_proc.arity == 0 or raise ArgumentError,
@@ -114,8 +112,8 @@ class Yahns::Config # :nodoc:
     end
 
     # this sets:
-    # :worker_atfork_prepare, :worker_atfork_parent, :worker_atfork_child
-    key = :"#{pfx}#{var}"
+    # :atfork_prepare, :atfork_parent, :atfork_child
+    key = var.to_sym
     @set[key] = [] unless @set.include?(key)
     @set[key] << my_proc
   end
@@ -403,7 +401,7 @@ class Yahns::Config # :nodoc:
     end
 
     [ :logger, :pid, :worker_processes, :user, :shutdown_timeout, :before_exec,
-      :worker_atfork_prepare, :worker_atfork_parent, :worker_atfork_child
+      :atfork_prepare, :atfork_parent, :atfork_child
     ].each do |var|
       val = @set[var]
       server.__send__("#{var}=", val) if val != :unset
diff --git a/lib/yahns/server.rb b/lib/yahns/server.rb
index 92adf52..330bcc8 100644
--- a/lib/yahns/server.rb
+++ b/lib/yahns/server.rb
@@ -14,9 +14,9 @@ class Yahns::Server # :nodoc:
   attr_writer :before_exec
   attr_writer :worker_processes
   attr_writer :shutdown_timeout
-  attr_writer :worker_atfork_prepare
-  attr_writer :worker_atfork_parent
-  attr_writer :worker_atfork_child
+  attr_writer :atfork_prepare
+  attr_writer :atfork_parent
+  attr_writer :atfork_child
   include Yahns::SocketHelper
 
   def initialize(config)
@@ -32,7 +32,7 @@ class Yahns::Server # :nodoc:
     @pid = nil
     @worker_processes = nil
     @before_exec = nil
-    @worker_atfork_prepare = @worker_atfork_parent = @worker_atfork_child = nil
+    @atfork_prepare = @atfork_parent = @atfork_child = nil
     @user = nil
     @queues = []
     @wthr = []
diff --git a/lib/yahns/server_mp.rb b/lib/yahns/server_mp.rb
index 4957c22..8272a9e 100644
--- a/lib/yahns/server_mp.rb
+++ b/lib/yahns/server_mp.rb
@@ -48,8 +48,8 @@ module Yahns::ServerMP # :nodoc:
     @sev = Yahns::Sigevent.new
     switch_user(*@user) if @user
     @user = @workers = nil
-    @worker_atfork_child.each(&:call) if @worker_atfork_child
-    @worker_atfork_child = @worker_atfork_parent = @worker_atfork_prepare = nil
+    @atfork_child.each(&:call) if @atfork_child
+    @atfork_child = @atfork_parent = @atfork_prepare = nil
   end
 
   def spawn_missing_workers
@@ -58,11 +58,11 @@ module Yahns::ServerMP # :nodoc:
       @workers.value?(worker_nr) and next
       worker = Yahns::Worker.new(worker_nr)
       @logger.info("worker=#{worker_nr} spawning...")
-      @worker_atfork_prepare.each(&:call) if @worker_atfork_parent
+      @atfork_prepare.each(&:call) if @atfork_parent
       if pid = fork
         @workers[pid] = worker.atfork_parent
         # XXX is this useful?
-        @worker_atfork_parent.each(&:call) if @worker_atfork_parent
+        @atfork_parent.each(&:call) if @atfork_parent
       else
         worker_atfork_internal(worker)
         run_mp_worker(worker)