<s> import os <EOL> __version__ = "<STR_LIT>" <EOL> __author__ = "<STR_LIT>" <EOL> __author_email__ = "<STR_LIT>" <EOL> __copyright__ = "<STR_LIT>" <EOL> __license__ = "<STR_LIT>" <EOL> __status__ = "<STR_LIT>" <EOL> __url__ = "<STR_LIT>" <EOL> UMASK = <NUM_LIT:0> <EOL> WORKDIR = "<STR_LIT:/>" <EOL> MAXFD = <NUM_LIT> <EOL> if ( hasattr ( os , "<STR_LIT>" ) ) : <EOL> REDIRECT_TO = os . devnull <EOL> else : <EOL> REDIRECT_TO = "<STR_LIT>" <EOL> def createDaemon ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> pid = os . fork ( ) <EOL> except OSError , e : <EOL> raise Exception , "<STR_LIT>" % ( e . strerror , e . errno ) <EOL> if ( pid == <NUM_LIT:0> ) : <EOL> os . setsid ( ) <EOL> try : <EOL> pid = os . fork ( ) <EOL> except OSError , e : <EOL> raise Exception , "<STR_LIT>" % ( e . strerror , e . errno ) <EOL> if ( pid == <NUM_LIT:0> ) : <EOL> os . chdir ( WORKDIR ) <EOL> os . umask ( UMASK ) <EOL> else : <EOL> os . _exit ( <NUM_LIT:0> ) <EOL> else : <EOL> os . _exit ( <NUM_LIT:0> ) <EOL> import resource <EOL> maxfd = resource . getrlimit ( resource . RLIMIT_NOFILE ) [ <NUM_LIT:1> ] <EOL> if ( maxfd == resource . RLIM_INFINITY ) : <EOL> maxfd = MAXFD <EOL> os . open ( REDIRECT_TO , os . O_RDWR ) <EOL> os . dup2 ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> os . dup2 ( <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> return ( <NUM_LIT:0> ) <EOL> def drop_privileges ( uid_name = '<STR_LIT>' , gid_name = '<STR_LIT>' ) : <EOL> if os . getuid ( ) != <NUM_LIT:0> : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> import pwd , grp <EOL> uid = pwd . getpwnam ( uid_name ) . pw_uid <EOL> gid = grp . getgrnam ( gid_name ) . gr_gid <EOL> os . setgroups ( [ ] ) <EOL> os . setgid ( gid ) <EOL> os . setuid ( uid ) <EOL> old_umask = os . umask ( <NUM_LIT:0> <NUM_LIT> ) </s>
