Skip to content

Log rotation doesn't copy file ownership #80

@regsmith

Description

@regsmith

If you create a file with user permissions but then run logger under root the file rotate will not preserve these permissions causing access issues.

% ls -al log.log 
-rw-r--r--  1 reginaldsmith  staff  0 23 Sep 11:17 log.log
% rvmsudo irb
2.7.2 :001 > require "logger"
 => true 
2.7.2 :004 > puts File.stat("log.log").uid
502
 => nil 
2.7.2 :005 > log = File.open("log.log", "a")
 => #<File:log.log> 
2.7.2 :006 > logger = Logger.new(log, "everytime")
 => #<Logger:0x00007fd7cfbc5ee0 @level=0, @progname=nil, @default_formatter=#<Logger::Formatter:0x00007fd7cfbc5eb8 @datetime_format=nil>, @formatte... 
2.7.2 :007 > logger.info "hello"
 => true 
2.7.2 :008 > puts File.stat("log.log").uid
0 
2.7.2 :010 > exit
% ls -al log.log
-rw-r--r--  1 root  staff  123 23 Sep 11:20 log.log
% irb
2.7.2 :001 > require "logger"
 => true 
2.7.2 :002 > log = File.open("log.log", "a")
Errno::EACCES (Permission denied @ rb_sysopen - log.log)
>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions