summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2014-05-16 11:53:02 -0300
committerTomás Touceda <chiiph@leap.se>2014-05-16 11:53:02 -0300
commitf995ff502089bcb7ef6a0fe71c692ee7274d45cb (patch)
tree6fad439ebef879fa4bd3a9f712700740068f1a50 /src
parent6175a790a31b4f987fe18cd6d046f2f53676b565 (diff)
parent4fe002c4a02d793964f99c62037c636ab0c64565 (diff)
Merge remote-tracking branch 'refs/remotes/irregulator/feature/5672' into develop
Diffstat (limited to 'src')
-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__":