7 # this reopens logs that have been rotated (using logrotate(8) or
8 # similar). It is recommended that you install
9 # A +File+ object is considered for reopening if it is:
10 # 1) opened with the O_APPEND and O_WRONLY flags
11 # 2) opened with an absolute path (starts with "/")
12 # 3) the current open file handle does not match its original open path
13 # 4) unbuffered (as far as userspace buffering goes)
14 # Returns the number of files reopened
17 ObjectSpace.each_object(File) do |fp|
19 next unless (fp.sync && fp.path[0..0] == "/")
21 flags = fp.fcntl(Fcntl::F_GETFL)
22 open_flags = File::WRONLY | File::APPEND
23 next unless (flags & open_flags) == open_flags
26 a, b = fp.stat, File.stat(fp.path)
27 next if a.ino == b.ino && a.dev == b.dev
30 fp.reopen(fp.path, "a")