]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
Install SIGTERM handler
authormmj <none@none>
Mon, 2 May 2005 18:56:38 +0000 (04:56 +1000)
committermmj <none@none>
Mon, 2 May 2005 18:56:38 +0000 (04:56 +1000)
ChangeLog
VERSION
src/mlmmj-send.c

index 1087b2364762f53d4e21380a911c2ef4df5456e4..004d6b521ff1d72ba07952e16b9b01a993e09686 100644 (file)
--- 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 c813fe116c9f9ea157ce22238b3ef8fc59524f30..fc5d2fae247417813cf2d519efeae5c44955a01b 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.2.5
+1.2.6pre2
index 60eaecbe7cfa38b43525d0ad9e165aad12acdde6..1e90b0a4c100ee876d8ace8740dec2570f97cb34 100644 (file)
@@ -41,6 +41,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <signal.h>
 
 #include "mlmmj.h"
 #include "mlmmj-send.h"
 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':