[Twisted-Python] Log file ownership

Glyph glyph at twistedmatrix.com
Wed Jun 13 15:15:34 EDT 2012


On Jun 11, 2012, at 12:21 AM, Flavio Grossi wrote:

> <exarkun <at> twistedmatrix.com> writes:
> 
> 
>> 
>> Log rotation - ie, renaming a file - isn't affected by the permissions 
>> of the log file.  The permissions of the *directory containing the log 
>> file* control whether it can be renamed (and a new one created) or not.
>> 
>> So it doesn't matter what permissions the log file has.  It only matters 
>> what permissions you set on the directory holding the log file.  That's 
>> outside of the control of twistd.
> 
> http://twistedmatrix.com/trac/browser/tags/releases/twisted-
> 12.0.0/twisted/python/logfile.py#L286
> 
> def rotate(self):
>    if not (os.access(self.directory, os.W_OK) and os.access(self.path, 
> os.W_OK)):
>        return
> 
> 
> it seems to also need write access to log file.

It's a pity that this code wasn't commented.  I can't find a platform where moving the file needs write access.  File a bug?  (Just another example of why LBYL is an antipattern...)

-glyph


More information about the Twisted-Python mailing list