diff options
-rw-r--r-- | src/lib/sos/plugintools.py | 2 | ||||
-rwxr-xr-x | src/sosreport | 29 |
2 files changed, 18 insertions, 13 deletions
diff --git a/src/lib/sos/plugintools.py b/src/lib/sos/plugintools.py index 8f8de4d8..d3b7a9d7 100644 --- a/src/lib/sos/plugintools.py +++ b/src/lib/sos/plugintools.py @@ -29,7 +29,7 @@ This is the base class for sosreport plugins """ from sos.helpers import * -from threading import Thread +from threading import Thread, activeCount import os, os.path, sys, string, itertools, glob, re class PluginBase: diff --git a/src/sosreport b/src/sosreport index 069f1a59..711475f1 100755 --- a/src/sosreport +++ b/src/sosreport @@ -35,27 +35,29 @@ from snack import * from threading import Thread, activeCount, enumerate import signal + +## Set up routines to be linked to signals for termination handling def exittermhandler(signum, frame): + doExitCode() + +def doExitCode(): if activeCount() > 1: print "SIGTERM received, multiple threads detected, waiting for all threads to exit" - for thread in enumerate: + for thread in enumerate(): thread.wait() print "All threads ended, cleaning up." else: print "SIGTERM received, cleaning up" - # Add code here to clean up /tmp - -def exitkillhandler(signum, frame): - if activeCount() > 1: - # Figure out how to kill threads and put that code here - else: - print "SIGKILL received, exiting without cleaning up. + # FIXME: Add code here to clean up /tmp sys.exit(255) - + # Handle any sort of exit signal cleanly -# Currently, we intercept only sig 9 and 15 (KILL and TERM) +# Currently, we intercept only sig 15 (TERM) signal.signal(signal.SIGTERM, exittermhandler) -signal.signal(signal.SIGKILL, exitkillhandler) + +## FIXME: Need to figure out how to IPC with child threads in case of +## multiple SIGTERMs. +## FIXME: Need to figure out how to handle SIGKILL - we can't intercept it. if os.getuid() != 0: @@ -352,4 +354,7 @@ def sosreport(): if __name__ == '__main__': - sosreport() + try: + sosreport() + except KeyboardInterrupt: + doExitCode()
\ No newline at end of file |