[PATCH] Make SIGHUP singal handler equivalent to SIGTERM and SIGINT.
xnox at debian.org
Tue Jun 5 04:04:10 BST 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 , 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
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
@@ -308,7 +308,8 @@ SAFE CONNECTION GUARANTEEING THE AUTHENTICITY OF YOUR IMAP SERVER!
-OfflineImap listens to the unix signals SIGUSR1 and SIGUSR2.
+OfflineImap listens to the unix signals SIGUSR1, SIGUSR2, SIGTERM,
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
Folder filtering and nametrans
diff --git a/offlineimap/init.py b/offlineimap/init.py
index 24d6c1a..94a9a18 100644
@@ -329,14 +329,14 @@ class OfflineImap:
def sig_handler(sig, frame):
- if sig == signal.SIGUSR1 or sig == signal.SIGHUP:
+ if sig == signal.SIGUSR1:
# tell each account to stop sleeping
elif sig == signal.SIGUSR2:
# tell each account to stop looping
getglobalui().warn("Terminating after this sync...")
- 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)...")
More information about the OfflineIMAP-project