Add signal handler for SIGTERM so objects can get cleaned up if managedsoftware update gets killed. This should cause launchd processes we've started (like for /usr/sbin/installer and /usr/sbin/softwareupdate) to be stopped as well.

This commit is contained in:
Greg Neagle
2012-08-16 13:47:30 -07:00
parent 703c8a7ff0
commit f1d8df900e
+13
View File
@@ -23,6 +23,7 @@ import optparse
import os
import re
#import stat
import signal
import subprocess
import sys
import time
@@ -58,6 +59,15 @@ from munkilib import FoundationPlist
from munkilib import utils
def signal_handler(signum, frame):
"""Handle any signals we've been told to.
Right now just handle SIGTERM so clean up can happen, like
garbage collection, which will trigger object destructors and
kill any launchd processes we've started."""
if signum == signal.SIGTERM:
sys.exit()
def getIdleSeconds():
"""Returns the number of seconds since the last mouse
or keyboard event."""
@@ -377,6 +387,9 @@ def notifyUserOfUpdates(force=False):
def main():
"""Main"""
# install handler for SIGTERM
signal.signal(signal.SIGTERM, signal_handler)
# check to see if we're root
if os.geteuid() != 0:
print >> sys.stderr, 'You must run this as root!'