Mercurial > hg > mlmmj
changeset 400:2c03919b9adf
Let's make sure we can get the exclusive lock before discarding mail:
--- 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)
author | mmj |
---|---|
date | Thu, 13 Jan 2005 21:19:46 +1100 |
parents | 152504e6be32 |
children | c60351e368bd |
files | src/mlmmj-maintd.c |
diffstat | 1 files changed, 18 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/mlmmj-maintd.c Thu Jan 13 19:57:32 2005 +1100 +++ b/src/mlmmj-maintd.c Thu Jan 13 21:19:46 2005 +1100 @@ -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)