From ed20b2fa1f9e733e24a17c7983d5b411623c4ecc Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Thu, 12 Feb 2009 15:08:59 -0500 Subject: add a excepthook handler for uncaught exceptions, so they get written to the log https://fedorahosted.org/func/ticket/70 --- certmaster/certmaster.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/certmaster/certmaster.py b/certmaster/certmaster.py index e4a3d17..506a029 100644 --- a/certmaster/certmaster.py +++ b/certmaster/certmaster.py @@ -16,7 +16,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # standard modules import SimpleXMLRPCServer +import string import sys +import traceback import os import os.path from OpenSSL import crypto @@ -323,9 +325,24 @@ def serve(xmlrpcinstance): xmlrpcinstance.audit_logger.logger.info("certmaster started") server.serve_forever() +def excepthook(exctype, value, tracebackobj): + exctype_blurb = "Exception occured: %s" % exctype + excvalue_blurb = "Exception value: %s" % value + exctb_blurb = "Exception Info:\n%s" % string.join(traceback.format_list(traceback.extract_tb(tracebackobj))) + + print exctype_blurb + print excvalue_blurb + print exctb_blurb + + log = logger.Logger().logger + log.info(exctype_blurb) + log.info(excvalue_blurb) + log.info(exctb_blurb) + def main(argv): - + + sys.excepthook = excepthook cm = CertMaster('/etc/certmaster/certmaster.conf') if "daemon" in argv or "--daemon" in argv: -- cgit