From: mmj Date: Thu, 13 Jan 2005 10:19:46 +0000 (+1100) Subject: Let's make sure we can get the exclusive lock before discarding mail: X-Git-Tag: RELEASE_1_2_0~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad876b7618ea1f6bb72ec8efbe6bd874af1eab80;p=thirdparty%2Fmlmmj.git 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) --- diff --git a/src/mlmmj-maintd.c b/src/mlmmj-maintd.c index 87fcf1d9..07f2fe5a 100644 --- a/src/mlmmj-maintd.c +++ b/src/mlmmj-maintd.c @@ -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)