;ò
µ“ÅAc           @   s™   d  Z  d Z d Z d k Z d k Z d k Z d „  Z e d j oR e ƒ  Z e	 d d ƒ i
 d e e i ƒ  e i ƒ  e i ƒ  f ƒ e i d	 ƒ n d S(
   s•  Disk And Execution MONitor (Daemon)

Default daemon behaviors (they can be modified):
   1.) Ignore SIGHUP signals.
   2.) Default current working directory to the "/" directory.
   3.) Set the current file creation mode mask to 0.
   4.) Close all open files (0 to [SC_OPEN_MAX or 256]).
   5.) Redirect standard I/O streams to "/dev/null".

Failed fork() calls will return a tuple: (errno, strerror).  This behavior
can be modified to meet your program's needs.

Resources:
   Advanced Programming in the Unix Environment: W. Richard Stevens
   Unix Network Programming (Volume 1): W. Richard Stevens
   http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
s   Chad J. Schroeders   $Id$Nc          C   s  y t  i ƒ  } Wn% t j
 o }  |  i |  i f Sn X| d j o” t  i ƒ  t i t i	 t i
 ƒ y t  i ƒ  } Wn% t j
 o }  |  i |  i f Sn X| d j o t  i d ƒ t  i d ƒ qæ t  i d ƒ n t  i d ƒ y t  i d ƒ } Wn t t f j
 o d } n Xx> t d | ƒ D]- } y t  i | ƒ Wq+t j
 o q+Xq+Wt  i d t  i ƒ t  i d t  i ƒ t  i d t  i ƒ d Sd S(   s_   Detach a process from the controlling terminal and run it in the
   background as a daemon.
   i    s   /s   SC_OPEN_MAXi   s	   /dev/nullN(   s   oss   forks   pids   OSErrors   es   errnos   strerrors   setsids   signals   SIGHUPs   SIG_IGNs   chdirs   umasks   _exits   sysconfs   maxfds   AttributeErrors
   ValueErrors   ranges   fds   closes   opens   O_RDONLYs   O_RDWR(   s   es   maxfds   pids   fd(    (    s   /home/jra/daemon.pys   createDaemon   s>     	
 	s   __main__s   createDaemon.logs   ws#   rc: %s; pid: %d; ppid: %d; pgrp: %di    (   s   __doc__s
   __author__s   __version__s   oss   syss   signals   createDaemons   __name__s   retCodes   opens   writes   getpids   getppids   getpgrps   exit(   s   retCodes   signals
   __author__s   syss   createDaemons   __version__s   os(    (    s   /home/jra/daemon.pys   ?   s   				I	8