about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-02-09 20:59:49 -0800
committerEric Wong <normalperson@yhbt.net>2009-02-09 20:59:49 -0800
commit4b5e01a32cb005dd890c32a78cf34150efc7a208 (patch)
tree0f82e93024013221500bf7f9137aecaf9c703630 /lib
parent8fd433875764163eb042a5d7489c2895677ddde1 (diff)
downloadunicorn-4b5e01a32cb005dd890c32a78cf34150efc7a208.tar.gz
If we're running in the foreground and don't care for process
manglement, then there's no need to start a pipe we won't need.
Diffstat (limited to 'lib')
-rw-r--r--lib/unicorn.rb22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index cacb395..3389846 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -71,14 +71,7 @@ module Unicorn
       @start_ctx = DEFAULT_START_CTX.dup
       @start_ctx.merge!(options[:start_ctx]) if options[:start_ctx]
       @purgatory = [] # prevents objects in here from being GC-ed
-
-      # this pipe is used to wake us up from select(2) in #join when signals
-      # are trapped.  See trap_deferred
-      @rd_sig, @wr_sig = IO.pipe.map do |io|
-        set_cloexec(io)
-        io.nonblock = true
-        io
-      end
+      @rd_sig = @wr_sig = nil
     end
 
     # Runs the thing.  Returns self so you can run join on it
@@ -140,7 +133,16 @@ module Unicorn
     # one-at-a-time time and we'll happily drop signals in case somebody
     # is signalling us too often.
     def join
+      # this pipe is used to wake us up from select(2) in #join when signals
+      # are trapped.  See trap_deferred
+      @rd_sig, @wr_sig = IO.pipe.map do |io|
+        set_cloexec(io)
+        io.nonblock = true
+        io
+      end unless (@rd_sig && @wr_sig)
+
       %w(QUIT INT TERM USR1 USR2 HUP).each { |sig| trap_deferred(sig) }
+
       begin
         loop do
           reap_all_workers
@@ -346,8 +348,8 @@ module Unicorn
     # by the user.
     def init_worker_process
       %w(TERM INT QUIT USR1 USR2 HUP).each { |sig| trap(sig, 'IGNORE') }
-      @rd_sig.close
-      @wr_sig.close
+      @rd_sig.close if @rd_sig
+      @wr_sig.close if @wr_sig
       @workers.values.each { |other| other.tempfile.close rescue nil }
       @workers.clear
       @start_ctx.clear