[Zodb-checkins] CVS: Zope/lib/python/zdaemon - Daemon.py:1.11.4.2 SignalPasser.py:NONE
Chris McDonough
chrism@zope.com
Tue, 8 Oct 2002 17:45:58 -0400
Update of /cvs-repository/Zope/lib/python/zdaemon
In directory cvs.zope.org:/tmp/cvs-serv17057/lib/python/zdaemon
Modified Files:
Tag: chrism-install-branch
Daemon.py
Removed Files:
Tag: chrism-install-branch
SignalPasser.py
Log Message:
More merges from HEAD.
=== Zope/lib/python/zdaemon/Daemon.py 1.11.4.1 => 1.11.4.2 ===
--- Zope/lib/python/zdaemon/Daemon.py:1.11.4.1 Mon Sep 2 03:35:10 2002
+++ Zope/lib/python/zdaemon/Daemon.py Tue Oct 8 17:45:57 2002
@@ -15,15 +15,24 @@
import os, sys, time, signal
from ZDaemonLogging import pstamp
import zLOG
-from SignalPasser import SignalPasser
pyth = sys.executable
class DieNow(Exception):
pass
-class DieNowWithError(Exception):
- pass
+class SignalPasser:
+ """ A class used for passing signal that the daemon receives along to
+ its child """
+ def __init__(self, pid):
+ self.pid = pid
+
+ def __call__(self, signum, frame):
+ # send the signal to our child
+ os.kill(self.pid, signum)
+ # we want to die ourselves if we're signaled with SIGTERM or SIGINT
+ if signum in [signal.SIGTERM, signal.SIGINT]:
+ raise DieNow
def run(argv, pidfile=''):
if os.environ.has_key('ZDAEMON_MANAGED'):
@@ -45,22 +54,16 @@
interesting = [1, 2, 3, 10, 12, 15]
# ie. HUP, INT, QUIT, USR1, USR2, TERM
for sig in interesting:
- signal.signal(sig, SignalPasser(sig))
+ signal.signal(sig, SignalPasser(pid))
pstamp('Houston, we have forked: pid %s' % pid, zLOG.INFO)
write_pidfile(pidfile)
p,s = wait(pid) # waitpid will block until child exit
if s:
- # 255 is a reserved status code which means
- # that a startup could not be executed, so we allow
- # our child to die if this status code is encountered.
- # Otherwise, continue and restart because our child died
- # with another nonzero exit code, meaning he bit it in
- # an unsavory way.
- if os.WIFEXITED(s) and os.WEXITSTATUS(s) == 255:
- raise DieNowWithError
- else:
- log_pid(p, s)
- continue
+ # continue and restart because our child died
+ # with a nonzero exit code, meaning he bit it in
+ # an unsavory way (likely a segfault or something)
+ log_pid(p, s)
+ continue
else:
# no need to restart, our child wanted to die.
raise DieNow
@@ -75,8 +78,6 @@
except DieNow:
sys.exit()
- except DieNowWithError:
- sys.exit(1)
def detach():
# do the funky chicken dance to detach from the terminal
@@ -90,7 +91,7 @@
def write_pidfile(pidfile):
if pidfile:
pf = open(pidfile, 'w+')
- pf.write(("%s" % os.getpid()))
+ pf.write(("%s\n" % os.getpid()))
pf.close()
def wait(pid):
@@ -132,8 +133,7 @@
signame = get_signal_name(signum)
msg = "stopped by signal %s(%s)" % (signame,
signum)
- pstamp('Aiieee! Process %s %s' % (p, msg),
- zLOG.ERROR)
+ pstamp('Aieeee! Process %s %s' % (p, msg), zLOG.ERROR)
_signals = None
=== Removed File Zope/lib/python/zdaemon/SignalPasser.py ===