about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-04-13 11:46:14 -0700
committerEric Wong <normalperson@yhbt.net>2009-04-13 12:01:20 -0700
commitf34618e64b254f7792b476acf2e7eb426aa551a2 (patch)
tree4d3e6ee0358e53667f1b512cb930afe4cd9d5911
parenta9d022298c194edf296d6d19ff97c8b8a6ce4839 (diff)
downloadunicorn-f34618e64b254f7792b476acf2e7eb426aa551a2.tar.gz
Instead of just worker.nr.  This is a configuration file/API
change and will break existing configurations.

This allows worker.tempfile to be exposed to the hooks
so ownership changes can still happen on it.

On the other hand, I don't know of many people actually
using this feature (or Unicorn).
-rw-r--r--lib/unicorn.rb4
-rw-r--r--lib/unicorn/configurator.rb18
-rw-r--r--test/exec/test_exec.rb6
-rw-r--r--test/unit/test_signals.rb2
4 files changed, 15 insertions, 15 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index c1e8fcd..4465109 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -389,7 +389,7 @@ module Unicorn
         tempfile = Tempfile.new('') # as short as possible to save dir space
         tempfile.unlink # don't allow other processes to find or see it
         worker = Worker.new(worker_nr, tempfile)
-        @before_fork.call(self, worker.nr)
+        @before_fork.call(self, worker)
         pid = fork { worker_loop(worker) }
         @workers[pid] = worker
       end
@@ -438,7 +438,7 @@ module Unicorn
       @start_ctx = @workers = @rd_sig = @wr_sig = nil
       @listeners.each { |sock| sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) }
       worker.tempfile.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
-      @after_fork.call(self, worker.nr) if @after_fork # can drop perms
+      @after_fork.call(self, worker) if @after_fork # can drop perms
       @request = HttpRequest.new(logger)
       build_app! unless @preload_app
     end
diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb
index 3fcb892..548c239 100644
--- a/lib/unicorn/configurator.rb
+++ b/lib/unicorn/configurator.rb
@@ -12,8 +12,8 @@ module Unicorn
   #   listen '0.0.0.0:9292'
   #   timeout 10
   #   pid "/tmp/my_app.pid"
-  #   after_fork do |server,worker_nr|
-  #     server.listen("127.0.0.1:#{9293 + worker_nr}") rescue nil
+  #   after_fork do |server,worker|
+  #     server.listen("127.0.0.1:#{9293 + worker.nr}") rescue nil
   #   end
   class Configurator
     # The default logger writes its output to $stderr
@@ -25,18 +25,18 @@ module Unicorn
       :listeners => [],
       :logger => DEFAULT_LOGGER,
       :worker_processes => 1,
-      :after_fork => lambda { |server, worker_nr|
-          server.logger.info("worker=#{worker_nr} spawned pid=#{$$}")
+      :after_fork => lambda { |server, worker|
+          server.logger.info("worker=#{worker.nr} spawned pid=#{$$}")
 
           # per-process listener ports for debugging/admin:
           # "rescue nil" statement is needed because USR2 will
           # cause the master process to reexecute itself and the
           # per-worker ports can be taken, necessitating another
           # HUP after QUIT-ing the original master:
-          # server.listen("127.0.0.1:#{8081 + worker_nr}") rescue nil
+          # server.listen("127.0.0.1:#{8081 + worker.nr}") rescue nil
         },
-      :before_fork => lambda { |server, worker_nr|
-          server.logger.info("worker=#{worker_nr} spawning...")
+      :before_fork => lambda { |server, worker|
+          server.logger.info("worker=#{worker.nr} spawning...")
         },
       :before_exec => lambda { |server|
           server.logger.info("forked child re-executing...")
@@ -97,13 +97,13 @@ module Unicorn
     # the worker after forking.  The following is an example hook which adds
     # a per-process listener to every worker:
     #
-    #  after_fork do |server,worker_nr|
+    #  after_fork do |server,worker|
     #    # per-process listener ports for debugging/admin:
     #    # "rescue nil" statement is needed because USR2 will
     #    # cause the master process to reexecute itself and the
     #    # per-worker ports can be taken, necessitating another
     #    # HUP after QUIT-ing the original master:
-    #    server.listen("127.0.0.1:#{9293 + worker_nr}") rescue nil
+    #    server.listen("127.0.0.1:#{9293 + worker.nr}") rescue nil
     #  end
     def after_fork(*args, &block)
       set_hook(:after_fork, block_given? ? block : args[0])
diff --git a/test/exec/test_exec.rb b/test/exec/test_exec.rb
index 67a189c..596ab88 100644
--- a/test/exec/test_exec.rb
+++ b/test/exec/test_exec.rb
@@ -39,8 +39,8 @@ end
 worker_processes 4
 timeout 30
 logger Logger.new('#{COMMON_TMP.path}')
-before_fork do |server, worker_nr|
-  server.logger.info "before_fork: worker=\#{worker_nr}"
+before_fork do |server, worker|
+  server.logger.info "before_fork: worker=\#{worker.nr}"
 end
   EOS
 
@@ -286,7 +286,7 @@ end
     File.unlink(tmp.path)
     ucfg = Tempfile.new('unicorn_test_config')
     ucfg.syswrite("listen '#@addr:#@port'\n")
-    ucfg.syswrite("before_fork { |s,nr|\n")
+    ucfg.syswrite("before_fork { |s,w|\n")
     ucfg.syswrite("  s.listen('#{tmp.path}', :backlog => 5, :sndbuf => 8192)\n")
     ucfg.syswrite("  s.listen('#@addr:#{port2}', :rcvbuf => 8192)\n")
     ucfg.syswrite("\n}\n")
diff --git a/test/unit/test_signals.rb b/test/unit/test_signals.rb
index 45de263..bedce01 100644
--- a/test/unit/test_signals.rb
+++ b/test/unit/test_signals.rb
@@ -30,7 +30,7 @@ class SignalsTest < Test::Unit::TestCase
     tmp.chmod(0)
     @server_opts = {
       :listeners => [ "127.0.0.1:#@port", @tmp.path ],
-      :after_fork => lambda { |server,worker_nr|
+      :after_fork => lambda { |server,worker|
         trap(:HUP) { tmp.chmod(n += 1) }
       },
     }