From 74215182d5fc24a209bf51d201cb5cfd2819f474 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 24 Apr 2009 13:52:37 -0700 Subject: cleanup: avoid duped self-pipe init/replacement logic We do this in both the worker and master processes, so avoid repeating ourselves. --- lib/unicorn.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 33be99a..d1c7eeb 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -179,7 +179,7 @@ module Unicorn def join # this pipe is used to wake us up from select(2) in #join when signals # are trapped. See trap_deferred - SELF_PIPE.replace(IO.pipe) + init_self_pipe! respawn = true QUEUE_SIGS.each { |sig| trap_deferred(sig) } @@ -449,7 +449,7 @@ module Unicorn SIG_QUEUE.clear proc_name "worker[#{worker.nr}]" START_CTX.clear - SELF_PIPE.each { |x| x.close rescue nil } + init_self_pipe! WORKERS.values.each { |other| other.tempfile.close! rescue nil } WORKERS.clear LISTENERS.each { |sock| sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) } @@ -463,9 +463,7 @@ module Unicorn @logger.info "worker=#{worker_nr} reopening logs..." Unicorn::Util.reopen_logs @logger.info "worker=#{worker_nr} done reopening logs" - SELF_PIPE.last.close rescue nil - SELF_PIPE.replace(IO.pipe) - SELF_PIPE.each { |io| io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) } + init_self_pipe! end # runs inside each forked worker, this sits around and waits @@ -478,8 +476,6 @@ module Unicorn alive = worker.tempfile # tempfile is our lifeline to the master process ready = LISTENERS client = nil - SELF_PIPE.replace(IO.pipe) - SELF_PIPE.each { |io| io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) } # closing anything we IO.select on will raise EBADF trap(:USR1) { nr = -65536; rd.close rescue nil } @@ -615,5 +611,11 @@ module Unicorn io.sync = true end + def init_self_pipe! + SELF_PIPE.each { |io| io.close rescue nil } + SELF_PIPE.replace(IO.pipe) + SELF_PIPE.each { |io| io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) } + end + end end -- cgit v1.2.3-24-ge0c7