about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-10-05 20:43:36 -0700
committerEric Wong <normalperson@yhbt.net>2009-10-05 20:43:36 -0700
commit09e93cd05506023d38c471bcbc8189447f800524 (patch)
tree6eed71c59812ebd3d219986c491045cdeff7ef58
parentd8d665495029bc8a102bdaf550ef618da64f36fe (diff)
downloadrainbows-09e93cd05506023d38c471bcbc8189447f800524.tar.gz
Avoid calling chmod on "false" leading to NoMethodError
and rely entirely on LISTENERS.first being valid.
-rw-r--r--lib/rainbows/thread_pool.rb12
-rw-r--r--lib/rainbows/thread_spawn.rb2
2 files changed, 6 insertions, 8 deletions
diff --git a/lib/rainbows/thread_pool.rb b/lib/rainbows/thread_pool.rb
index fc44cac..77bd275 100644
--- a/lib/rainbows/thread_pool.rb
+++ b/lib/rainbows/thread_pool.rb
@@ -26,11 +26,11 @@ module Rainbows
 
       # closing anything we IO.select on will raise EBADF
       trap(:USR1) { reopen_worker_logs(worker.nr) rescue nil }
-      trap(:QUIT) { alive = false; LISTENERS.map! { |s| s.close rescue nil } }
+      trap(:QUIT) { LISTENERS.map! { |s| s.close rescue nil } }
       [:TERM, :INT].each { |sig| trap(sig) { exit(0) } } # instant shutdown
       logger.info "worker=#{worker.nr} ready with ThreadPool"
 
-      while alive && master_pid == Process.ppid
+      while LISTENERS.first && master_pid == Process.ppid
         maintain_thread_count(threads)
         threads.list.each do |thr|
           alive.chmod(nr += 1)
@@ -65,11 +65,9 @@ module Rainbows
 
     def new_worker_thread
       Thread.new {
-        alive = true
-        thr = Thread.current
         begin
           ret = begin
-            thr[:t] = Time.now
+            Thread.current[:t] = Time.now
             IO.select(LISTENERS, nil, nil, timeout/2.0) or next
           rescue Errno::EINTR
             retry
@@ -83,11 +81,11 @@ module Rainbows
             end
           end
         rescue Object => e
-          if alive
+          if LISTENERS.first
             logger.error "Unhandled listen loop exception #{e.inspect}."
             logger.error e.backtrace.join("\n")
           end
-        end while alive = LISTENERS.first
+        end while LISTENERS.first
       }
     end
 
diff --git a/lib/rainbows/thread_spawn.rb b/lib/rainbows/thread_spawn.rb
index 5d7e68e..7dcd2e4 100644
--- a/lib/rainbows/thread_spawn.rb
+++ b/lib/rainbows/thread_spawn.rb
@@ -22,7 +22,7 @@ module Rainbows
 
       # closing anything we IO.select on will raise EBADF
       trap(:USR1) { reopen_worker_logs(worker.nr) rescue nil }
-      trap(:QUIT) { alive = false; LISTENERS.map! { |s| s.close rescue nil } }
+      trap(:QUIT) { LISTENERS.map! { |s| s.close rescue nil } }
       [:TERM, :INT].each { |sig| trap(sig) { exit(0) } } # instant shutdown
       logger.info "worker=#{worker.nr} ready with ThreadSpawn"