[Zope-Checkins] CVS: ZODB3/zdaemon - zdrun.py:188.8.131.52
jeremy at zope.com
Fri Sep 19 17:02:55 EDT 2003
Update of /cvs-repository/ZODB3/zdaemon
In directory cvs.zope.org:/tmp/cvs-serv11418/zdaemon
Restore comment deleted by the merge of ZODB3-3_2-branch.
=== ZODB3/zdaemon/zdrun.py 184.108.40.206 => 220.127.116.11 ===
--- ZODB3/zdaemon/zdrun.py:18.104.22.168 Mon Sep 15 17:26:59 2003
+++ ZODB3/zdaemon/zdrun.py Fri Sep 19 17:02:54 2003
@@ -317,6 +317,28 @@
self.waitstatus = pid, sts
+ # To daemonize, we need to become the leader of our own session
+ # (process) group. If we do not, signals sent to our
+ # parent process will also be sent to us. This might be bad because
+ # signals such as SIGINT can be sent to our parent process during
+ # normal (uninteresting) operations such as when we press Ctrl-C in the
+ # parent terminal window to escape from a logtail command.
+ # To disassociate ourselves from our parent's session group we use
+ # os.setsid. It means "set session id", which has the effect of
+ # disassociating a process from is current session and process group
+ # and setting itself up as a new session leader.
+ # Unfortunately we cannot call setsid if we're already a session group
+ # leader, so we use "fork" to make a copy of ourselves that is
+ # guaranteed to not be a session group leader.
+ # We also change directories, set stderr and stdout to null, and
+ # change our umask.
+ # This explanation was (gratefully) garnered from
+ # http://www.hawklord.uklinux.net/system/daemons/d3.htm
pid = os.fork()
if pid != 0:
@@ -563,7 +585,7 @@
"backoff=%r\n" % self.backoff +
"lasttime=%r\n" % self.proc.lasttime +
"application=%r\n" % self.proc.pid +
- "manager=%r\n" % os.getpid() +
+ "manager=%r\n" % os.getpid() +
"backofflimit=%r\n" % self.options.backofflimit +
"filename=%r\n" % self.proc.filename +
"args=%r\n" % self.proc.args)
@@ -631,7 +653,7 @@
"""Decode the status returned by wait() or waitpid().
Return a tuple (exitstatus, message) where exitstatus is the exit
status, or -1 if the process was killed by a signal; and message
is a message telling what happened. It is the caller's
@@ -689,9 +711,9 @@
# Main program
assert os.name == "posix", "This code makes many Unix-specific assumptions"
d = Daemonizer()
More information about the Zope-Checkins