about summary refs log tree commit homepage
path: root/lib
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 /lib
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).
Diffstat (limited to 'lib')
-rw-r--r--lib/unicorn.rb4
-rw-r--r--lib/unicorn/configurator.rb18
2 files changed, 11 insertions, 11 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])