Move signal code into gajim.py

The reason for signal.signal(signal.SIGPIPE, signal.SIG_DFL)

Python ignores SIGPIPE by default ( signal(SIGPIPE, SIG_IGN) )
Write on a socket return then an error 32 EPIPE, which naturally
turns into an exception.

signal.SIG_DFL restores normal UNIX behavior
This commit is contained in:
Philipp Hörist 2018-05-17 20:57:21 +02:00
parent 72df2524e9
commit 4731e8491b
2 changed files with 4 additions and 6 deletions

View File

@ -55,10 +55,6 @@ except Exception:
randomsource = random.Random()
randomsource.seed()
import signal
if os.name != 'nt':
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
if os.name == 'nt':
import certifi
import OpenSSL.crypto

View File

@ -78,7 +78,7 @@ def _init_gtk():
from gajim.application import GajimApplication
application = GajimApplication()
_install_terminate(application)
_install_sginal_handlers(application)
application.run(sys.argv)
@ -100,13 +100,15 @@ def _set_proc_title():
libc.setproctitle('gajim')
def _install_terminate(application):
def _install_sginal_handlers(application):
def sigint_cb(num, stack):
print('SIGINT/SIGTERM received')
application.quit()
# ^C exits the application normally
signal.signal(signal.SIGINT, sigint_cb)
signal.signal(signal.SIGTERM, sigint_cb)
if os.name != 'nt':
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
def main():