From c7739a2259798859ddb2827fd6f90366813e5212 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 8 Jun 2010 06:41:36 +0000 Subject: reopen_logs: avoid modifying ObjectSpace while iterating Creating File objects while iterating ObjectSpace for File objects may hit subtle bugs. It may only be safe in MRI, and even then it's not behavior that sounds sane to rely on. So stop doing it. --- lib/unicorn/util.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/unicorn/util.rb b/lib/unicorn/util.rb index 458b6d7..28f41e5 100644 --- a/lib/unicorn/util.rb +++ b/lib/unicorn/util.rb @@ -22,6 +22,7 @@ module Unicorn ! fp.closed? && fp.sync && + fp.path && fp.path[0] == ?/ && (fp.fcntl(Fcntl::F_GETFL) & append_flags) == append_flags end @@ -41,10 +42,11 @@ module Unicorn # 4) unbuffered (as far as userspace buffering goes, not O_SYNC) # Returns the number of files reopened def reopen_logs + to_reopen = [] nr = 0 + ObjectSpace.each_object(File) { |fp| is_log?(fp) and to_reopen << fp } - ObjectSpace.each_object(File) do |fp| - is_log?(fp) or next + to_reopen.each do |fp| orig_st = fp.stat begin b = File.stat(fp.path) @@ -64,7 +66,8 @@ module Unicorn fp.chown(orig_st.uid, orig_st.gid) end nr += 1 - end # each_object + end + nr end -- cgit v1.2.3-24-ge0c7