1 # -*- encoding: binary -*-
10 # for easier env["rack.input"] compatibility
21 append_flags = File::WRONLY | File::APPEND
26 (fp.fcntl(Fcntl::F_GETFL) & append_flags) == append_flags
29 def chown_logs(uid, gid)
30 ObjectSpace.each_object(File) do |fp|
31 fp.chown(uid, gid) if is_log?(fp)
35 # This reopens ALL logfiles in the process that have been rotated
36 # using logrotate(8) (without copytruncate) or similar tools.
37 # A +File+ object is considered for reopening if it is:
38 # 1) opened with the O_APPEND and O_WRONLY flags
39 # 2) opened with an absolute path (starts with "/")
40 # 3) the current open file handle does not match its original open path
41 # 4) unbuffered (as far as userspace buffering goes, not O_SYNC)
42 # Returns the number of files reopened
46 ObjectSpace.each_object(File) do |fp|
50 b = File.stat(fp.path)
51 next if orig_st.ino == b.ino && orig_st.dev == b.dev
56 if fp.respond_to?(:external_encoding) && enc = fp.external_encoding
57 open_arg << ":#{enc.to_s}"
58 enc = fp.internal_encoding and open_arg << ":#{enc.to_s}"
60 fp.reopen(fp.path, open_arg)
63 if orig_st.uid != new_st.uid || orig_st.gid != new_st.gid
64 fp.chown(orig_st.uid, orig_st.gid)
71 # creates and returns a new File object. The File is unlinked
72 # immediately, switched to binary mode, and userspace output
73 # buffering is disabled
76 TmpIO.open("#{Dir::tmpdir}/#{rand}",
77 File::RDWR|File::CREAT|File::EXCL, 0600)