[PATCH] Make SIGHUP singal handler equivalent to SIGTERM and SIGINT.

Dmitrijs Ledkovs xnox at debian.org
Tue Jun 5 03:04:10 UTC 2012


offlineimap has several frontends that encourage running it from a
terminal under an X session. When X session closes for a system
shutdown, the terminals exit, after sending SIGHUP to their children.

Previously SIGHUP was treated to be equivalent to SIGUSR1, i.e. wake
up and sync all accounts. This causes delays during shutdown.

According to Wikipedia [0], SIGHUP has been repurposed from a
historical meaning to one of:
 * re-read configuration files, or reinitialize (e.g. Apache, sendmail)
 * controlling pseudo or virtual terminal has been closed

I believe second meaning is more appropriate for offlineimap, and
hence this patch makes SIGHUP to be handled in the same way SIGTERM
and SIGINT are handled.

This patch also adds documentation of the current handling of
SIGTERM/SIGINT/SIGHUP signals.

[0] http://en.wikipedia.org/wiki/SIGHUP

Debian-Bug: http://bugs.debian.org/670120
Reported-By: Steve Langasek <steve.langasek at canonical.com>
Signed-off-by: Dmitrijs Ledkovs <xnox at debian.org>
---
 docs/MANUAL.rst     |    9 ++++++++-
 offlineimap/init.py |    4 ++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/docs/MANUAL.rst b/docs/MANUAL.rst
index 96d5d91..0e080a1 100644
--- a/docs/MANUAL.rst
+++ b/docs/MANUAL.rst
@@ -308,7 +308,8 @@ SAFE CONNECTION GUARANTEEING THE AUTHENTICITY OF YOUR IMAP SERVER!
 UNIX Signals
 ============
 
-OfflineImap listens to the unix signals SIGUSR1 and SIGUSR2.
+OfflineImap listens to the unix signals SIGUSR1, SIGUSR2, SIGTERM,
+SIGINT, SIGHUP:
 
 If sent a SIGUSR1 it will abort any current (or next future) sleep of all
 accounts that are configured to "autorefresh". In effect, this will trigger a
@@ -319,6 +320,12 @@ accounts will abort any current sleep and will exit after a currently running
 synchronization has finished. This signal can be used to gracefully exit out of
 a running offlineimap "daemon".
 
+SIGTERM, SIGINT, SIGHUP are all treated to gracefully terminate as
+soon as possible. This means it will finish syncing the current folder
+in each account, close keep alive connections, remove locks on the
+accounts and exit. It may take up to 10 seconds, if autorefresh option
+is used.
+
 Folder filtering and nametrans
 ==============================
 
diff --git a/offlineimap/init.py b/offlineimap/init.py
index 24d6c1a..94a9a18 100644
--- a/offlineimap/init.py
+++ b/offlineimap/init.py
@@ -329,14 +329,14 @@ class OfflineImap:
                     syncaccounts.append(account)
 
             def sig_handler(sig, frame):
-                if sig == signal.SIGUSR1 or sig == signal.SIGHUP:
+                if sig == signal.SIGUSR1:
                     # tell each account to stop sleeping
                     accounts.Account.set_abort_event(self.config, 1)
                 elif sig == signal.SIGUSR2:
                     # tell each account to stop looping
                     getglobalui().warn("Terminating after this sync...")
                     accounts.Account.set_abort_event(self.config, 2)
-                elif sig == signal.SIGTERM or sig == signal.SIGINT:
+                elif sig in (signal.SIGTERM, signal.SIGINT, signal.SIGHUP):
                     # tell each account to ABORT ASAP (ctrl-c)
                     getglobalui().warn("Terminating NOW (this may "\
                                        "take a few seconds)...")
-- 
1.7.10




More information about the OfflineIMAP-project mailing list