diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2011-01-05 16:02:37 +0100 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2011-01-05 16:02:37 +0100 |
commit | 4b823abec78b352fc446ef3da90258188bd3eb87 (patch) | |
tree | 6ecb3326da484dfa74be194bc06c5ef91079c926 | |
parent | 3076a53f7589ff3eed8ebbe9ad66da6f4fc506b1 (diff) | |
download | logilab-common-4b823abec78b352fc446ef3da90258188bd3eb87.tar.gz |
daemon: daemonize can be specified an umask to use, and return different exit code according to process
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | daemon.py | 14 |
2 files changed, 17 insertions, 6 deletions
@@ -1,13 +1,19 @@ ChangeLog for logilab.common ============================ +-- + * daemon: we can now specify umask to daemonize function, and it return + different exit code according to the process + + 2010-11-15 -- 0.53.0 - * python3.x: first python3.x release + * first python3.x compatible release * __init__: tempattr context manager * shellutils: progress context manager + 2010-10-11 -- 0.52.1 * configuration: fix pb with option names as unicode string w/ python 2.5. Makes OptionError available through the module @@ -19,7 +25,6 @@ ChangeLog for logilab.common * modutils: Consider arch-specific installation for STD_LIB_DIR definition - 2010-09-28 -- 0.52.0 * testlib is now based on unittest2, to prepare its own extinction. Warning are printed so you can easily migration step by step. @@ -27,7 +27,12 @@ import time import warnings -def daemonize(pidfile=None, uid=None): +def daemonize(pidfile=None, uid=None, umask=077): + """daemonize a Unix process. Set paranoid umask by default. + + Return 1 in the original process, 2 in the first fork, and None for the + second fork (eg daemon process). + """ # See http://www.erlenstar.demon.co.uk/unix/faq_toc.html#TOC16 # XXX unix specific # @@ -40,11 +45,12 @@ def daemonize(pidfile=None, uid=None): # as a non-session group leader, we can never regain a controlling # terminal. if os.fork(): # launch child again. - return 1 + return 2 # move to the root to avoit mount pb os.chdir('/') - # set paranoid umask - os.umask(077) + # set umask if specified + if umask is not None: + os.umask(umask) # redirect standard descriptors null = os.open('/dev/null', os.O_RDWR) for i in range(3): |