]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
Let's make sure we can get the exclusive lock before discarding mail:
authormmj <none@none>
Thu, 13 Jan 2005 10:19:46 +0000 (21:19 +1100)
committermmj <none@none>
Thu, 13 Jan 2005 10:19:46 +0000 (21:19 +1100)
--- mlmmj-maintd.c      12 Nov 2004 01:28:32 -0000      1.42
+++ mlmmj-maintd.c      13 Jan 2005 10:19:04 -0000
@@ -178,16 +178,29 @@
 {
        struct stat st;
        time_t t;
+       int fd, ret = 0;
+
+       fd = open(old, O_RDWR);
+       if(fd < 0)
+               return 0;
+
+       if(myexcllock(fd) < 0) {
+               close(fd);
+               return 0;
+       }

        stat(old, &st);
        t = time(NULL);

-       if(t - st.st_mtime > age) {
-               rename(old, new);
-               return 1;
-       }
+       if(t - st.st_mtime > age)
+               if(rename(old, new) < 0)
+                       ret = 0;
+               else
+                       ret = 1;

-       return 0;
+       myunlock(fd);
+       close(fd);
+       return ret;
 }

 int resend_queue(const char *listdir, const char *mlmmjsend)

src/mlmmj-maintd.c

index 87fcf1d9f631ae3be5e44fe6ed8941a673ace9d3..07f2fe5a9949e30bd8c78c76fb8a93af44aeb9c0 100644 (file)
@@ -178,16 +178,29 @@ int discardmail(const char *old, const char *new, time_t age)
 {
        struct stat st;
        time_t t;
+       int fd, ret = 0;
+
+       fd = open(old, O_RDWR);
+       if(fd < 0)
+               return 0;
+
+       if(myexcllock(fd) < 0) {
+               close(fd);
+               return 0;
+       }
 
        stat(old, &st);
        t = time(NULL);
 
-       if(t - st.st_mtime > age) {
-               rename(old, new);
-               return 1;
-       }
+       if(t - st.st_mtime > age)
+               if(rename(old, new) < 0)
+                       ret = 0;
+               else
+                       ret = 1;
 
-       return 0;
+       myunlock(fd);
+       close(fd);
+       return ret;
 }
 
 int resend_queue(const char *listdir, const char *mlmmjsend)