diff options
author | jwbernin <jwbernin@ef72aa8b-4018-0410-8976-d6e080ef94d8> | 2007-01-27 17:05:37 +0000 |
---|---|---|
committer | jwbernin <jwbernin@ef72aa8b-4018-0410-8976-d6e080ef94d8> | 2007-01-27 17:05:37 +0000 |
commit | f487724c84b43adc8cb60b8c41db7741d9acc958 (patch) | |
tree | 9888f22639c17085de45747948b892c128541578 | |
parent | 61cc7f9cc5db61271c58518ec202718f85a1d976 (diff) | |
download | sos-f487724c84b43adc8cb60b8c41db7741d9acc958.tar.gz |
Starting attempt at handling SIGTERM, SIGKILL gracefully via signal()
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/sos/trunk@70 ef72aa8b-4018-0410-8976-d6e080ef94d8
-rwxr-xr-x | src/sosreport | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/sosreport b/src/sosreport index 1acbc681..069f1a59 100755 --- a/src/sosreport +++ b/src/sosreport @@ -32,7 +32,31 @@ from optparse import OptionParser import sos.policyredhat from sos.helpers import * from snack import * -from threading import Thread +from threading import Thread, activeCount, enumerate +import signal + +def exittermhandler(signum, frame): + if activeCount() > 1: + print "SIGTERM received, multiple threads detected, waiting for all threads to exit" + 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. + sys.exit(255) + +# Handle any sort of exit signal cleanly +# Currently, we intercept only sig 9 and 15 (KILL and TERM) +signal.signal(signal.SIGTERM, exittermhandler) +signal.signal(signal.SIGKILL, exitkillhandler) + if os.getuid() != 0: print 'You must run sosreport as root!' |