From: Simon Schubert <2@0x2c.org> Date: Mon, 28 Jun 2010 22:49:53 +0000 (+0200) Subject: catch SIGHUP so that sleeps can be interrupted by the user X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=247523d6ea29cfb4df93a2fa197bb7b0f0ca8c0f;p=people%2Fms%2Fdma.git catch SIGHUP so that sleeps can be interrupted by the user 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 (earlier version) --- diff --git a/dma.c b/dma.c index 61cae68..7012bba 100644 --- 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)