# HG changeset patch # User mmj # Date 1115060198 -36000 # Node ID e0922d60370648fd4b8b5a41bad749d0f52a19a9 # Parent 1a2f00c5b2e934e2eaf5123d65985c447500d27b Install SIGTERM handler diff -r 1a2f00c5b2e9 -r e0922d603706 ChangeLog --- a/ChangeLog Tue May 03 04:20:15 2005 +1000 +++ b/ChangeLog Tue May 03 04:56:38 2005 +1000 @@ -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 -r 1a2f00c5b2e9 -r e0922d603706 VERSION --- a/VERSION Tue May 03 04:20:15 2005 +1000 +++ b/VERSION Tue May 03 04:56:38 2005 +1000 @@ -1,1 +1,1 @@ -1.2.5 +1.2.6pre2 diff -r 1a2f00c5b2e9 -r e0922d603706 src/mlmmj-send.c --- a/src/mlmmj-send.c Tue May 03 04:20:15 2005 +1000 +++ b/src/mlmmj-send.c Tue May 03 04:56:38 2005 +1000 @@ -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 @@ 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 @@ 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 @@ 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':