]> mj.ucw.cz Git - umpf.git/commitdiff
and fix it a bit
authorAnicka Bernathova <anicka@anicka.net>
Fri, 29 Aug 2008 16:03:02 +0000 (18:03 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Fri, 29 Aug 2008 16:03:02 +0000 (18:03 +0200)
lock.c

diff --git a/lock.c b/lock.c
index b7e3ef49d7d2fb40be24f4214fd0dda1c370ae0d..219f199f32ba16812654c6618c30c5d5063c4955 100644 (file)
--- 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;