1 # -*- encoding: binary -*-
7 append_flags = File::WRONLY | File::APPEND
11 (fp.fcntl(Fcntl::F_GETFL) & append_flags) == append_flags
12 rescue IOError, Errno::EBADF
16 def self.chown_logs(uid, gid)
17 ObjectSpace.each_object(File) do |fp|
18 fp.chown(uid, gid) if is_log?(fp)
23 # This reopens ALL logfiles in the process that have been rotated
24 # using logrotate(8) (without copytruncate) or similar tools.
25 # A +File+ object is considered for reopening if it is:
26 # 1) opened with the O_APPEND and O_WRONLY flags
27 # 2) the current open file handle does not match its original open path
28 # 3) unbuffered (as far as userspace buffering goes, not O_SYNC)
29 # Returns the number of files reopened
31 # In Unicorn 3.5.x and earlier, files must be opened with an absolute
32 # path to be considered a log file.
36 ObjectSpace.each_object(File) { |fp| is_log?(fp) and to_reopen << fp }
38 to_reopen.each do |fp|
41 rescue IOError, Errno::EBADF
46 b = File.stat(fp.path)
47 next if orig_st.ino == b.ino && orig_st.dev == b.dev
52 File.open(fp.path, 'a') { |tmpfp| fp.reopen(tmpfp) }
56 # this should only happen in the master:
57 if orig_st.uid != new_st.uid || orig_st.gid != new_st.gid
58 fp.chown(orig_st.uid, orig_st.gid)
62 rescue IOError, Errno::EBADF
63 # not much we can do...