changeset 401:c60351e368bd

Grab the lock right after we start sending, and not release before completely done with it. --- mlmmj-send.c 25 Nov 2004 15:59:34 -0000 1.66 +++ mlmmj-send.c 13 Jan 2005 16:27:50 -0000 @@ -600,11 +600,17 @@ /* initialize file with mail to send */ - if((mailfd = open(mailfilename, O_RDONLY)) < 0) { + if((mailfd = open(mailfilename, O_RDWR)) < 0) { log_error(LOG_ARGS, "Could not open '%s'", mailfilename); exit(EXIT_FAILURE); } + if(myexcllock(mailfd) < 0) { + log_error(LOG_ARGS, "Could not lock '%s'." + "Mail not sent!", mailfilename); + exit(EXIT_FAILURE); + } + if(fstat(mailfd, &st) < 0) { log_error(LOG_ARGS, "Could not stat mailfd"); exit(EXIT_FAILURE); @@ -868,7 +874,7 @@ close(sockfd); munmap(mailmap, st.st_size); close(mailfd); - + if(archive) { if(!ctrlarchive) rename(mailfilename, archivefilename); @@ -878,5 +884,9 @@ } else if(deletewhensent) unlink(mailfilename); + if(myunlock(mailfd) < 0) + log_error(LOG_ARGS, "Could not unlock '%s'", mailfilename); + + return EXIT_SUCCESS; }
author mmj
date Fri, 14 Jan 2005 03:28:38 +1100
parents 2c03919b9adf
children f085a74cf050
files src/listcontrol.c src/log_oper.c src/mlmmj-send.c
diffstat 3 files changed, 76 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/listcontrol.c	Thu Jan 13 21:19:46 2005 +1100
+++ b/src/listcontrol.c	Fri Jan 14 03:28:38 2005 +1100
@@ -103,7 +103,7 @@
 	const char *subswitch;
 	size_t len;
 	struct stat stbuf;
-	int closedlist, nosubconfirm, tmpfd;
+	int closedlist, nosubconfirm, tmpfd, noget;
 	size_t cmdlen;
 	unsigned int ctrl;
 	
@@ -418,17 +418,18 @@
 		exit(EXIT_FAILURE);
 		break;
 
-	/* listname+bounces-user=example.tld-INDEX@domain.tld */
+	/* listname+bounces-INDEX-user=example.tld@domain.tld */
 	case CTRL_BOUNCES:
-		bouncenr = strrchr(param, '-');
-		if (!bouncenr) { /* malformed bounce, ignore and clean up */
+		bouncenr = param;
+		c = strchr(param, '-');
+		if (!c) { /* malformed bounce, ignore and clean up */
 			unlink(mailname);
 			exit(EXIT_SUCCESS);
 		}
-		*bouncenr++ = '\0';
+		*c++ = '\0';
 		execlp(mlmmjbounce, mlmmjbounce,
 				"-L", listdir,
-				"-a", param,
+				"-a", c,
 				"-m", mailname,
 				"-n", bouncenr, NULL);
 		log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjbounce);
@@ -464,6 +465,9 @@
 	/* listname+get-INDEX@domain.tld */
 	case CTRL_GET:
 		unlink(mailname);
+		noget = statctrl(listdir, "noget");
+		if(noget)
+			exit(EXIT_SUCCESS);
 		/* sanity check--is it all digits? */
 		for(c = param; *c != '\0'; c++) {
 			if(!isdigit((int)*c))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/log_oper.c	Fri Jan 14 03:28:38 2005 +1100
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "mlmmj.h"
+#include "log_error.h"
+#include "log_oper.h"
+
+int log_oper(const char *logfilename, const char *str)
+{
+	char ct[26], *logstr;
+	struct stat st;
+	time_t t;
+
+	if(lstat(logfilename, &st) < 0 && errno != ENOENT) {
+		log_error(LOG_ARGS, "Could not stat logfile %s", logfilename);
+		return -1;
+	} else if((st.st_mode & S_IFMT) == S_IFLNK) {
+		log_error(LOG_ARGS, "%s is a symbolic link, not opening",
+					logfilename);
+		return -1;
+	}
+	
+	fd = open(logfilename, O_RDWR|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR);
+	if(fd < 0) {
+		log_error(LOG_ARGS, "Could not open %s", logfilename);
+		return -1;
+	}
+
+	if((time(&t) == (time_t)-1) || (ctime_r(&t, ct) == NULL))
+		strncpy(ct, "Unknown time", sizeof(ct));
+
+	if(myexcllock(fd) < 0) {
+		log_error(LOG_ARGS, "Could not lock %s", logfilename);
+		return -1;
+	}
+
+	logstr = concatstr(4, ct, ":", str, "\n");
+	if(writen(fd, logstr, strlen(logstr)) < 0)
+		log_error(LOG_ARGS, "Could not write to %s", logfilename);
+	
+	if(myunlock(fd) < 0)
+		log_error(LOG_ARGS, "Could not unlock %s", logfilename);
+
+	close(fd);
+	myfree(logstr);
+	
+	return 0;
+}
--- a/src/mlmmj-send.c	Thu Jan 13 21:19:46 2005 +1100
+++ b/src/mlmmj-send.c	Fri Jan 14 03:28:38 2005 +1100
@@ -600,11 +600,17 @@
 	
 	/* initialize file with mail to send */
 
-	if((mailfd = open(mailfilename, O_RDONLY)) < 0) {
+	if((mailfd = open(mailfilename, O_RDWR)) < 0) {
 	        log_error(LOG_ARGS, "Could not open '%s'", mailfilename);
 		exit(EXIT_FAILURE);
 	}
 
+	if(myexcllock(mailfd) < 0) {
+		log_error(LOG_ARGS, "Could not lock '%s'."
+				"Mail not sent!", mailfilename);
+		exit(EXIT_FAILURE);
+	}
+
 	if(fstat(mailfd, &st) < 0) {
 		log_error(LOG_ARGS, "Could not stat mailfd");
 		exit(EXIT_FAILURE);
@@ -878,5 +884,9 @@
 	} else if(deletewhensent)
 		unlink(mailfilename);
 
+	if(myunlock(mailfd) < 0)
+		log_error(LOG_ARGS, "Could not unlock '%s'", mailfilename);
+	
+
 	return EXIT_SUCCESS;
 }