From f53b56938ffcf5992b729bb7dbaa83bf7cfcb4f3 Mon Sep 17 00:00:00 2001 From: Anicka Bernathova Date: Fri, 29 Aug 2008 18:03:02 +0200 Subject: [PATCH] and fix it a bit --- lock.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lock.c b/lock.c index b7e3ef4..219f199 100644 --- a/lock.c +++ b/lock.c @@ -48,6 +48,7 @@ dot_lock(char* path) if ((fd = open(lockfile, O_WRONLY | O_EXCL | O_CREAT, 0)) >= 0) { close(fd); + res = 0; break; } @@ -94,8 +95,10 @@ open_mailbox(char* path, int use_default_mailbox) /* we are not going to create default mailbox */ fd = open(path, O_RDWR); - if (fd < 0) - return -1; + if (fd < 0){ + dot_unlock(path); + return -1; + } /* hide it again */ setresgid(ruid, ruid, suid); @@ -104,11 +107,15 @@ open_mailbox(char* path, int use_default_mailbox) if (fd < 0 && errno == ENOENT){ fd = open(path, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); - if (fd < 0) + if (fd < 0){ + dot_unlock(path); return -1; + } - } else if (fd < 0) - return -1; + } else if (fd < 0){ + dot_unlock(path); + return -1; + } } /* fcntl then */ @@ -148,7 +155,7 @@ main(int argc, char** argv) char* mb = argv[1]; getresgid(&ruid, &euid, &suid); setresgid(ruid, ruid, euid); - fd = open_mailbox(mb, 1); + fd = open_mailbox(mb, 0); printf("%d\n", fd); if (fd < 0) return 1; -- 2.39.2