commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/common/src GServerApp.py


From: Jason Cater
Subject: gnue/common/src GServerApp.py
Date: Wed, 01 May 2002 20:18:22 -0400

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    02/05/01 20:18:21

Modified files:
        common/src     : GServerApp.py 

Log message:
        added comments to the daemonize code

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/GServerApp.py.diff?cvsroot=OldCVS&tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: gnue/common/src/GServerApp.py
diff -c gnue/common/src/GServerApp.py:1.4 gnue/common/src/GServerApp.py:1.5
*** gnue/common/src/GServerApp.py:1.4   Tue Apr 30 19:52:30 2002
--- gnue/common/src/GServerApp.py       Wed May  1 20:18:21 2002
***************
*** 16,22 ****
  # write to the Free Software Foundation, Inc., 59 Temple Place
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # Copyright 2000, 2001 Free Software Foundation
  #
  # FILE:
  # GServerApp.py
--- 16,22 ----
  # write to the Free Software Foundation, Inc., 59 Temple Place
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # Copyright 2000-2002 Free Software Foundation
  #
  # FILE:
  # GServerApp.py
***************
*** 27,33 ****
  # NOTES:
  # This will eventually have features only needed by "server"
  # applications, such as abstracted client RPC calls via
! # CORBA, RPC-XML, SOAP, etc and daemon/forking/threading. 
  #
  
  from GBaseApp import GBaseApp
--- 27,33 ----
  # NOTES:
  # This will eventually have features only needed by "server"
  # applications, such as abstracted client RPC calls via
! # CORBA, RPC-XML, SOAP, etc and daemon/forking/threading.
  #
  
  from GBaseApp import GBaseApp
***************
*** 61,82 ****
    def run(self):
  
      # Fork, if applicable/possible, and send to background
!     if not self.OPTIONS["foreground"]: 
        self.daemonize()
  
  
    # Called when a request to shutdown the server is received
!   def shutdown(self): 
      pass
  
  
!   # Turn ourselves into a daemon/service/etc. 
    # Returns 1 if program successfully converted,
!   # 0 otherwise. 
!   # 
!   def daemonize(self): 
  
!     try: 
        # Fork #1
        pid = os.fork()
        if pid != 0:
--- 61,89 ----
    def run(self):
  
      # Fork, if applicable/possible, and send to background
!     if not self.OPTIONS["foreground"]:
        self.daemonize()
  
  
    # Called when a request to shutdown the server is received
!   def shutdown(self):
      pass
  
  
!   # Turn ourselves into a daemon/service/etc.
    # Returns 1 if program successfully converted,
!   # 0 otherwise.
!   #
!   def daemonize(self):
! 
!     # For an overview of what we're doing here,
!     # check out the Unix Programmer's FAQ at:
!     # http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
  
!     # We enclose these actions in try: blocks so that
!     # this doesn't fail on non-Unix environments.
! 
!     try:
        # Fork #1
        pid = os.fork()
        if pid != 0:
***************
*** 84,122 ****
          sys.exit(0)
  
        # Open new filehandles for stdin, stdout, stderr
        sin = open('/dev/null','r')
        sout = open('/dev/null','w')
        serr = open('/dev/null','w')
  
!     except AttributeError: 
        return 0
!     except IOError: 
        return 0
      except OSError:
        return 0
  
  
      # Disassociate ourselves
!     try: 
        os.chdir('/')
        os.setsid()
        os.umask(0)
!     except AttributeError: 
        pass
      except OSError:
        pass
  
  
!     try: 
        # Fork #2
        pid = os.fork()
!       if pid != 0: 
          sys.exit(0)
!     except OSError: 
        pass
  
  
!     try: 
        sys.stdin.close()
        sys.stdin = sin
  
--- 91,132 ----
          sys.exit(0)
  
        # Open new filehandles for stdin, stdout, stderr
+       # TODO: This may eventually be log files. 
        sin = open('/dev/null','r')
        sout = open('/dev/null','w')
        serr = open('/dev/null','w')
  
!     except AttributeError:
        return 0
!     except IOError:
        return 0
      except OSError:
        return 0
  
  
      # Disassociate ourselves
!     try:
        os.chdir('/')
        os.setsid()
        os.umask(0)
!     except AttributeError:
        pass
      except OSError:
        pass
  
  
!     try:
        # Fork #2
        pid = os.fork()
!       if pid != 0:
          sys.exit(0)
!     except OSError:
        pass
  
  
!     # Redirect all the stdio channels.
!     # (after all, we have no terminal :)
!     try:
        sys.stdin.close()
        sys.stdin = sin
  
***************
*** 125,131 ****
  
        sys.stderr.close()
        sys.stderr = serr
!     except AttributeError: 
        pass
  
      return 1
--- 135,141 ----
  
        sys.stderr.close()
        sys.stderr = serr
!     except AttributeError:
        pass
  
      return 1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]