]> git.ipfire.org Git - people/ms/dma.git/commitdiff
catch SIGHUP so that sleeps can be interrupted by the user
authorSimon Schubert <2@0x2c.org>
Mon, 28 Jun 2010 22:49:53 +0000 (00:49 +0200)
committerSimon Schubert <2@0x2c.org>
Mon, 28 Jun 2010 22:50:56 +0000 (00:50 +0200)
A SIGHUP sent to the dma process will run the no-op signal handler and
break the sleep(3) call in deliver.
Do not increase the backoff if sleep was interrupted.

Submitted-by: Peter Pentchev <roam@ringlet.net> (earlier version)
dma.c

diff --git a/dma.c b/dma.c
index 61cae6839c944b54cb09cf7f691116d16544f9d1..7012bba556a1869ed49640556cc96d29a0f48941 100644 (file)
--- a/dma.c
+++ b/dma.c
@@ -82,6 +82,12 @@ struct config config = {
 };
 
 
+static void
+sighup_handler(int signo)
+{
+       (void)signo;    /* so that gcc doesn't complain */
+}
+
 static char *
 set_from(struct queue *queue, const char *osender)
 {
@@ -294,8 +300,8 @@ retry:
                                 MAX_TIMEOUT);
                        goto bounce;
                }
-               sleep(backoff);
-               backoff *= 2;
+               if (sleep(backoff) == 0)
+                       backoff *= 2;
                if (backoff > MAX_RETRY)
                        backoff = MAX_RETRY;
                goto retry;
@@ -358,6 +364,7 @@ show_queue(struct queue *queue)
 int
 main(int argc, char **argv)
 {
+       struct sigaction act;
        char *sender = NULL;
        struct queue queue;
        int i, ch;
@@ -472,6 +479,12 @@ skipopts:
 
        /* XXX fork root here */
 
+       act.sa_handler = sighup_handler;
+       act.sa_flags = 0;
+       sigemptyset(&act.sa_mask);
+       if (sigaction(SIGHUP, &act, NULL) != 0)
+               syslog(LOG_WARNING, "can not set signal handler: %m");
+
        parse_conf(CONF_PATH);
 
        if (config.authpath != NULL)