summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/app.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/bitmask/app.py')
-rw-r--r--src/leap/bitmask/app.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/leap/bitmask/app.py b/src/leap/bitmask/app.py
index 146743b5..e413ab4c 100644
--- a/src/leap/bitmask/app.py
+++ b/src/leap/bitmask/app.py
@@ -76,6 +76,16 @@ def sigint_handler(*args, **kwargs):
mainwindow = args[0]
mainwindow.quit()
+def sigterm_handler(*args, **kwargs):
+ """
+ Signal handler for SIGTERM.
+ This handler is actually passed to twisted reactor
+ """
+ logger = kwargs.get('logger', None)
+ if logger:
+ logger.debug("SIGTERM catched. shutting down...")
+ mainwindow = args[0]
+ mainwindow.quit()
def add_logger_handlers(debug=False, logfile=None, replace_stdout=True):
"""
@@ -314,6 +324,9 @@ def main():
sigint_window = partial(sigint_handler, window, logger=logger)
signal.signal(signal.SIGINT, sigint_window)
+ # callable used in addSystemEventTrigger to handle SIGTERM
+ sigterm_window = partial(sigterm_handler, window, logger=logger)
+
if IS_MAC:
window.raise_()
@@ -324,6 +337,12 @@ def main():
l = LoopingCall(QtCore.QCoreApplication.processEvents, 0, 10)
l.start(0.01)
+
+ # SIGTERM can't be handled the same way SIGINT is, since it's
+ # caught by twisted. See _handleSignals method in
+ # twisted/internet/base.py#L1150. So, addSystemEventTrigger
+ # reactor's method is used.
+ reactor.addSystemEventTrigger('before', 'shutdown', sigterm_window)
reactor.run()
if __name__ == "__main__":