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