Author Julien.Palard
Recipients Julien.Palard
Date 2013-05-15.13:49:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1368625795.57.0.786028186823.issue17981@psf.upfronthosting.co.za>
In-reply-to
Content
I have a script that close its socket to /dev/log immediatly before using it, causing it to fail, here is the code :
{{{
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import logging.handlers
import daemon
from daemon.pidlockfile import PIDLockFile

logger = logging.getLogger('twitterCounter')
logger.addHandler(logging.handlers.SysLogHandler(address='/dev/log'))
logger.setLevel(logging.DEBUG)

logger.info("Hello")

with daemon.DaemonContext():
    logger.info("World !")
}}}

and here is an strace :
{{{
strace -s999 -f  /tmp/test.py 2>&1 | grep -C2 ^connect
// Outside daemonContext, all is OK
// Note that inside daemonContext, all is OK if we do not log outside daemonContext.

close(3)                                = 0
socket(PF_FILE, SOCK_DGRAM, 0)          = 3
connect(3, {sa_family=AF_FILE, path="/dev/log"}, 10) = 0
sendto(3, "<14>Hello\0", 10, 0, NULL, 0) = 10
getuid()                                = 1001
--

// Second log, inside daemonContext, with the erroneous "socket(); close()" :


socket(PF_FILE, SOCK_DGRAM, 0)          = 3
close(3)                                = 0
connect(3, {sa_family=AF_FILE, path="/dev/log"}, 10) = -1 EBADF (Bad file descriptor)
close(3)                                = -1 EBADF (Bad file descriptor)

// As the previous try has failed, SysLogHandler seems to give another try with different parameters, failing too as expected socket type is DGRAM :
socket(PF_FILE, SOCK_STREAM, 0)         = 3
connect(3, {sa_family=AF_FILE, path="/dev/log"}, 10) = -1 EPROTOTYPE (Protocol wrong type for socket)
}}}
History
Date User Action Args
2013-05-15 13:49:55Julien.Palardsetrecipients: + Julien.Palard
2013-05-15 13:49:55Julien.Palardsetmessageid: <1368625795.57.0.786028186823.issue17981@psf.upfronthosting.co.za>
2013-05-15 13:49:55Julien.Palardlinkissue17981 messages
2013-05-15 13:49:54Julien.Palardcreate