changeset 335:64540601d8a8

Don't reuse listdir, but introduce a new variable.
author mmj
date Mon, 13 Sep 2004 04:13:52 +1000
parents 0a3a4868fd3c
children 6232225251c7
files include/mlmmj.h src/mlmmj-maintd.c
diffstat 2 files changed, 29 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/include/mlmmj.h	Sat Sep 11 08:48:42 2004 +1000
+++ b/include/mlmmj.h	Mon Sep 13 04:13:52 2004 +1000
@@ -41,7 +41,7 @@
 #define WAITPROBE 43200   /* How long do we wait for a bounce of the probe
 			     mail before concluding the address is no longer
 			     bouncing? 43200 is 12 hours */
-#define MAINTD_SLEEP 7200 /* How long between maintenance runs when
+#define MAINTD_SLEEP 120 /* How long between maintenance runs when
 			     mlmmj-maintd runs daemonized? 7200s is 2 hours */
 #define MAINTD_LOGFILE "mlmmj-maintd.lastrun.log"
 
--- a/src/mlmmj-maintd.c	Sat Sep 11 08:48:42 2004 +1000
+++ b/src/mlmmj-maintd.c	Mon Sep 13 04:13:52 2004 +1000
@@ -744,9 +744,11 @@
 		    const char *mlmmjbounce, const char *mlmmjunsub)
 {
 	char *random, *logname, *logstr;
+	char timenow[64];
 	struct stat st;
 	int maintdlogfd;
 	uid_t uid = getuid();
+	time_t t;
 
 	if(!listdir)
 		return;
@@ -786,6 +788,12 @@
 		return;
 	}
 
+	t = time(NULL);
+	if(ctime_r(&t, timenow))
+		WRITEMAINTLOG4(3, "Starting maintenance run at ",
+				timenow, "\n");
+
+
 	WRITEMAINTLOG4(3, "clean_moderation(", listdir, ");\n");
 	clean_moderation(listdir);
 
@@ -833,7 +841,7 @@
 {
 	int opt, daemonize = 1, ret;
 	char *bindir, *listdir = NULL, *mlmmjsend, *mlmmjbounce, *mlmmjunsub;
-	char *dirlists = NULL, *s;
+	char *dirlists = NULL, *s, *listiter;
 	struct stat st;
 	struct dirent *dp;
 	DIR *dirp;
@@ -881,10 +889,10 @@
 	myfree(bindir);
 
 	if(daemonize) {
-		if(listdir)
+		if(dirlists)
+			ret = mydaemon(dirlists);
+		else
 			ret = mydaemon(listdir);
-		else
-			ret = mydaemon(dirlists);
 	}
 
 	if(daemonize && ret < 0) {
@@ -900,6 +908,12 @@
 			continue;
 		}
 
+		if(chdir(dirlists) < 0) {
+			log_error(LOG_ARGS, "Could not chdir(%s).",
+					dirlists);
+			exit(EXIT_FAILURE);
+		}
+
 		if((dirp = opendir(dirlists)) == NULL) {
 			log_error(LOG_ARGS, "Could not opendir(%s).",
 					dirlists);
@@ -914,33 +928,33 @@
 					(strcmp(dp->d_name, ".") == 0))
 				continue;
 			
-			listdir = concatstr(3, dirlists, "/", dp->d_name);
+			listiter = concatstr(3, dirlists, "/", dp->d_name);
 
-			if(stat(listdir, &st) < 0) {
+			if(stat(listiter, &st) < 0) {
 				log_error(LOG_ARGS, "Could not stat(%s)",
-						listdir);
-				myfree(listdir);
+						listiter);
+				myfree(listiter);
 				continue;
 			}
 
 			if(!S_ISDIR(st.st_mode)) {
-				myfree(listdir);
+				myfree(listiter);
 				continue;
 			}
 
-			s = concatstr(2, listdir, "/control/listaddress");
+			s = concatstr(2, listiter, "/control/listaddress");
 			ret = stat(s, &st);
 			myfree(s);
 
-			if(ret < 0) { /* If ret < 0 it's not a listdir */
-				myfree(listdir);
+			if(ret < 0) { /* If ret < 0 it's not a listiter */
+				myfree(listiter);
 				continue;
 			}
 
-			do_maintenance(listdir, mlmmjsend, mlmmjbounce,
+			do_maintenance(listiter, mlmmjsend, mlmmjbounce,
 					mlmmjunsub);
 
-			myfree(listdir);
+			myfree(listiter);
 		}
 
 		closedir(dirp);