diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-06-08 06:41:36 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-06-08 06:41:36 +0000 |
commit | c7739a2259798859ddb2827fd6f90366813e5212 (patch) | |
tree | 1632271090a4d9ad8dff03ba5b73a7bafb17f11a /lib/unicorn/util.rb | |
parent | 765ff628e11775a9b684759d6c191b4934ff78fb (diff) | |
download | unicorn-c7739a2259798859ddb2827fd6f90366813e5212.tar.gz |
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.
Diffstat (limited to 'lib/unicorn/util.rb')
-rw-r--r-- | lib/unicorn/util.rb | 9 |
1 files 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 |