diff options
author | irregulator <irregulator@riseup.net> | 2014-05-13 17:05:14 +0300 |
---|---|---|
committer | irregulator <irregulator@riseup.net> | 2014-05-15 18:22:11 +0300 |
commit | 4fe002c4a02d793964f99c62037c636ab0c64565 (patch) | |
tree | 9a03461e9e7457fd25f9f7cc985f27e9eb1e053e /src/leap/bitmask | |
parent | 89cd9fd12532190143bcc14619f03126895a13fa (diff) |
Gracefully handle SIGTERM as well as SIGINT, feature #5672
SIGTERM is caught by twisted, so we have to use addSystemEventTrigger()
to pass a custom handler to twisted reactor.
See https://leap.se/code/issues/5672 for more.
Diffstat (limited to 'src/leap/bitmask')
-rw-r--r-- | src/leap/bitmask/app.py | 19 |
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__": |