From: mmj Date: Mon, 2 May 2005 18:56:38 +0000 (+1000) Subject: Install SIGTERM handler X-Git-Tag: RELEASE_1_2_12_RC1~90 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cabfe69860c76e2dc5db2cd4abb01f64a52e6ab5;p=thirdparty%2Fmlmmj.git Install SIGTERM handler --- diff --git a/ChangeLog b/ChangeLog index 1087b236..004d6b52 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + o Install SIGTERM handler in mlmmj-send to allow it to shut down gracefully o Also remove mails when it's a bounce from a person not subbed o Introduce read() wrapper (Stevens) o Bouncing confirmation mails of sub or unsub should be cleaned from diff --git a/VERSION b/VERSION index c813fe11..fc5d2fae 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.2.5 +1.2.6pre2 diff --git a/src/mlmmj-send.c b/src/mlmmj-send.c index 60eaecbe..1e90b0a4 100644 --- a/src/mlmmj-send.c +++ b/src/mlmmj-send.c @@ -41,6 +41,7 @@ #include #include #include +#include #include "mlmmj.h" #include "mlmmj-send.h" @@ -64,6 +65,14 @@ static int addtohdr = 0; static int prepmailinmem = 0; static int maxverprecips = MAXVERPRECIPS; +static int gotsigterm = 0; + +void catch_sig_term(int sig) +{ + /* We should only get SIGTERM here, but better safe than sorry */ + if(sig == SIGTERM) + gotsigterm = 1; +} char *bounce_from_adr(const char *recipient, const char *listadr, const char *mailfilename) @@ -374,6 +383,11 @@ int send_mail_verp(int sockfd, struct strlist *addrs, char *mailmap, return MLMMJ_FROM; } for(i = 0; i < addrs->count; i++) { + if(gotsigterm) { + log_error(LOG_ARGS, "TERM signal recieved, " + "shutting down."); + return -1; + } if(strchr(addrs->strs[i], '@') == NULL) { errno = 0; log_error(LOG_ARGS, "No @ in address, ignoring %s", @@ -573,8 +587,9 @@ int send_mail_many_list(int sockfd, const char *from, const char *replyto, hdrs, hdrslen, body, bodylen); myfree(bounceaddr); } - if(res && listaddr && archivefilename) { - /* we failed, so save the addresses and bail */ + if((res || gotsigterm) && listaddr && archivefilename) { + /* we failed or got a SIGTERM, so save the addresses + * and bail */ index = mybasename(archivefilename); return requeuemail(listdir, index, addrs, i); } @@ -640,6 +655,10 @@ int main(int argc, char **argv) mlmmjbounce = concatstr(2, bindir, "/mlmmj-bounce"); myfree(bindir); + /* install signal handler for SIGTERM */ + if(signal(SIGTERM, catch_sig_term) == SIG_ERR) + log_error(LOG_ARGS, "Could not install SIGTERM handler!"); + while ((opt = getopt(argc, argv, "aVDhm:l:L:R:F:T:r:s:")) != -1){ switch(opt) { case 'a':