diff options
author | Magnus Ahltorp <map@kth.se> | 2014-11-18 15:46:23 +0100 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2014-11-18 15:49:08 +0100 |
commit | d01f3c4b8ca72d722aff8ac6ac4346e089f319a6 (patch) | |
tree | 81369ebd6d2968ddfed388afd46c62bbd248b56b | |
parent | 5847ef948baeadf4582234f4c3e7ecff2791b4cf (diff) |
Catch ctrl-c more correctly. Catch SystemExit from add_chain and exit in main process instead
-rwxr-xr-x | tools/submitcert.py | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/tools/submitcert.py b/tools/submitcert.py index 80a3e37..2bb0c1a 100755 --- a/tools/submitcert.py +++ b/tools/submitcert.py @@ -13,6 +13,7 @@ import hashlib import itertools from certtools import * import os +import signal from multiprocessing import Pool @@ -32,7 +33,10 @@ def submitcert(certfile): certs = get_certs_from_file(certfile) timing_point(timing, "readcerts") - result = add_chain(baseurl, {"chain":map(base64.b64encode, certs)}) + try: + result = add_chain(baseurl, {"chain":map(base64.b64encode, certs)}) + except SystemExit: + return None timing_point(timing, "addchain") @@ -42,10 +46,13 @@ def submitcert(certfile): timing_point(timing, "checksig") except AssertionError, e: print "ERROR:", e - sys.exit(1) + return None + except urllib2.HTTPError, e: + print "ERROR:", e + return None except ecdsa.keys.BadSignatureError, e: print "ERROR: bad signature" - sys.exit(1) + return None if lookup_in_log: @@ -91,8 +98,15 @@ def submitcert(certfile): timing_point(timing, "lookup") return timing["deltatimes"] -p = Pool(1) - -for timing in p.imap_unordered(submitcert, certfiles): - print timing - +p = Pool(1, lambda: signal.signal(signal.SIGINT, signal.SIG_IGN)) + +try: + for timing in p.imap_unordered(submitcert, certfiles): + if timing == None: + p.terminate() + p.join() + sys.exit(1) + print timing +except KeyboardInterrupt: + p.terminate() + p.join() |