logging.py: mutiple system users writing to same file getting permission errors.

2007-12-06 Thread evenrik
An a redhat box I have root, apache and other normal users run code
that uses the logging module to write to the same log file.  Since
umasks are set to 2 or 022 this gets permission errors.

I have fixed my issue by patching the logging code everywhere there is
an open for write with:
try:
old_umask = os.umask(0)
# open for write here
finally:
os.umask(old_umask)

Is there a better way to solve this issue?
Are there any security problems with this solution other than the log
file not being protected?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: logging.py: mutiple system users writing to same file getting permission errors.

2007-12-10 Thread evenrik
On Dec 7, 12:46 pm, Vinay Sajip <[EMAIL PROTECTED]> wrote:
> On Dec 6, 6:35 pm, evenrik <[EMAIL PROTECTED]> wrote:
>
> > An a redhat box I have root, apache and other normal users run code
> > that uses theloggingmodule to write to the same log file.  Since
> > umasks are set to 2 or 022 this gets permission errors.
>
> > I have fixed my issue by patching theloggingcode everywhere there is
> > an open for write with:
> > try:
> > old_umask = os.umask(0)
> > # open for write here
> > finally:
> > os.umask(old_umask)
>
> > Is there a better way to solve this issue?
> > Are there any security problems with this solution other than the log
> > file not being protected?
>
> Multiple processes writing to the same log file may step on each
> other's toes: logging contains thread synchronisation code but no
> protection against multiple processes accessing the same resource. The
> best solution would be to log from all processes to a SocketHandler,
> and then have a socket receiver process write the logs to file. This
> effectively serialises access to the log file. An example is given in
> the logging docs, see
>
> http://docs.python.org/lib/network-logging.html
>
> Of course, you can have the receiver process run under a uid of your
> choosing which has the appropriate permissions to write to the log
> file.
>
> Regards,
>
> Vinay Sajip

Thank you for the warning about multiple processes.  We decided to try
creating a DBHandler to write the logs to PostgeSQL.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking if a text file is blank

2008-04-20 Thread evenrik
On Apr 20, 2:04 pm, [EMAIL PROTECTED] wrote:
> Greetings!
>
> I've just started learning python, so this is probably one of those
> obvious questions newbies ask.
>
> Is there any way in python to check if a text file is blank?
>
> What I've tried to do so far is:
>
> f = file("friends.txt", "w")
> if f.read() is True:
> """do stuff"""
> else:
> """do other stuff"""
> f.close()
>
> What I *mean* to do in the second line is to check if the text file is
> not-blank. But apparently that's not the way to do it.
>
> Could someone set me straight please?

I use os.path.getsize(path) for this purpose.
-- 
http://mail.python.org/mailman/listinfo/python-list