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

[minion-cvs] Complete the daemonize logic: release any mounts we are...



Update of /home/minion/cvsroot/src/minion/lib/mixminion/server
In directory moria.mit.edu:/tmp/cvs-serv20212/lib/mixminion/server

Modified Files:
	ServerMain.py 
Log Message:
Complete the daemonize logic: release any mounts we are holding busy, and umask 0.

Index: ServerMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/ServerMain.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- ServerMain.py	29 Dec 2002 21:00:48 -0000	1.12
+++ ServerMain.py	31 Dec 2002 04:38:00 -0000	1.13
@@ -373,15 +373,28 @@
 def daemonize():
     """Put the server into daemon mode with the standard trickery."""
     # ??? This 'daemonize' logic should go in Common.
+
+    # This logic is more-or-less verbatim from Stevens's _Advanced
+    # Programming in the Unix Environment_:
+
+    # Fork, to run in the background.
     pid = os.fork()
     if pid != 0:
         os._exit(0)
+    # Call 'setsid' to make ourselves a new session.
     if hasattr(os, 'setsid'):
         # Setsid is not available everywhere.
         os.setsid()
+    # Chdir to / so that we don't hold the CWD unnecessarily.
+    os.chdir(os.path.normpath("/")) #???? Is this right on Win32?
+    # Set umask to 000 so that we drop any (possibly nutty) umasks that
+    # our users had before.
+    os.umask(0000)
+    # Close all unused fds.
     sys.stderr.close()
     sys.stdout.close()
     sys.stdin.close()
+    # Override stdout and stderr in case some code tries to use them
     sys.stdout = LogStream("STDOUT", "WARN")
     sys.stderr = LogStream("STDERR", "WARN")