From: Vrinda Narayan Date: Wed, 13 Mar 2019 09:53:43 +0000 (+0530) Subject: Catch Keyboard Interrupt and exit cleanly. X-Git-Tag: 1.1.0rc1~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9bc790115a4cdaf56740d2596088da4663c7c9d6;p=thirdparty%2Fsuricata-update.git Catch Keyboard Interrupt and exit cleanly. Optimization #2878 https://redmine.openinfosecfoundation.org/issues/2878 Can be done by importing python library signal, and defining a function signal_handler which will print a message if keyboard interrupt is detected and exit the program. --- diff --git a/suricata/update/main.py b/suricata/update/main.py index ab995e3..ac5ab15 100644 --- a/suricata/update/main.py +++ b/suricata/update/main.py @@ -32,6 +32,7 @@ import shutil import glob import io import tempfile +import signal try: # Python 3. @@ -1472,7 +1473,12 @@ def _main(): return 0 +def signal_handler(signal, frame): + print('Program interrupted. Aborting...') + sys.exit(1) + def main(): + signal.signal(signal.SIGINT, signal_handler) try: sys.exit(_main()) except exceptions.ApplicationError as err: