From eb2bd80851d8fe066aab056836171b4f40df62aa Mon Sep 17 00:00:00 2001 From: Chris Smart Date: Sat, 21 Jan 2017 21:36:59 +1100 Subject: [PATCH] init: register SIGABRT and handle as per SIGUSR2 systemd supports a watchdog (via the WatchdogSec service file option) which will send the program a SIGABRT when the timer expires, however currently this causes offlineimap to be killed immediately. This patch registers SIGABRT and handles it in the same manner as SIGUSR2, so that the current synchronisation is completed before the program exits safely. This makes offlineimap more flexible and robust for persistent setups that make use of holdconnectionopen and autorefresh options. For example, it may be useful in assisting with the occasional situation where offlineimap may not return successfully after a suspend and resume. To make use of this, users could add the following to the [Service] section of their systemd offlineimap service file (restart every 5 minutes): Restart=on-watchdog WatchdogSec=300 Signed-off-by: Chris Smart Signed-off-by: Nicolas Sebrecht --- offlineimap/init.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/offlineimap/init.py b/offlineimap/init.py index 7f193d1..ad7f982 100644 --- a/offlineimap/init.py +++ b/offlineimap/init.py @@ -416,7 +416,7 @@ class OfflineImap(object): if sig == signal.SIGUSR1: # tell each account to stop sleeping accounts.Account.set_abort_event(self.config, 1) - elif sig == signal.SIGUSR2: + elif sig in (signal.SIGUSR2, signal.SIGABRT): # tell each account to stop looping getglobalui().warn("Terminating after this sync...") accounts.Account.set_abort_event(self.config, 2) @@ -442,6 +442,7 @@ class OfflineImap(object): signal.signal(signal.SIGHUP, sig_handler) signal.signal(signal.SIGUSR1, sig_handler) signal.signal(signal.SIGUSR2, sig_handler) + signal.signal(signal.SIGABRT, sig_handler) signal.signal(signal.SIGTERM, sig_handler) signal.signal(signal.SIGINT, sig_handler) signal.signal(signal.SIGQUIT, sig_handler)