1 # -*- encoding: binary -*-
11 append_flags = File::WRONLY | File::APPEND
16 (fp.fcntl(Fcntl::F_GETFL) & append_flags) == append_flags
17 rescue IOError, Errno::EBADF
21 def chown_logs(uid, gid)
22 ObjectSpace.each_object(File) do |fp|
23 fp.chown(uid, gid) if is_log?(fp)
27 # This reopens ALL logfiles in the process that have been rotated
28 # using logrotate(8) (without copytruncate) or similar tools.
29 # A +File+ object is considered for reopening if it is:
30 # 1) opened with the O_APPEND and O_WRONLY flags
31 # 2) opened with an absolute path (starts with "/")
32 # 3) the current open file handle does not match its original open path
33 # 4) unbuffered (as far as userspace buffering goes, not O_SYNC)
34 # Returns the number of files reopened
38 ObjectSpace.each_object(File) { |fp| is_log?(fp) and to_reopen << fp }
40 to_reopen.each do |fp|
43 rescue IOError, Errno::EBADF
48 b = File.stat(fp.path)
49 next if orig_st.ino == b.ino && orig_st.dev == b.dev
54 File.open(fp.path, 'a') { |tmpfp| fp.reopen(tmpfp) }
58 # this should only happen in the master:
59 if orig_st.uid != new_st.uid || orig_st.gid != new_st.gid
60 fp.chown(orig_st.uid, orig_st.gid)
64 rescue IOError, Errno::EBADF
65 # not much we can do...