]> mj.ucw.cz Git - umpf.git/commitdiff
cope with old locks
authorAnicka Bernathova <anicka@anicka.net>
Fri, 17 Jul 2009 10:22:44 +0000 (12:22 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Fri, 17 Jul 2009 10:22:44 +0000 (12:22 +0200)
lock.c

diff --git a/lock.c b/lock.c
index 5aa6a7aab0d01b75553bc76f589a627d35c6c66d..12f40830b4e4f4bee8b4846556b986e8cb6d221c 100644 (file)
--- a/lock.c
+++ b/lock.c
@@ -8,6 +8,7 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <sys/stat.h>
+#include <time.h>
 
 #include "umpf.h"
 
@@ -55,7 +56,6 @@ cat(char* l, char* r)
        return res;     
 }
 
-/* FIXME: what about privileges? */
 static int
 dot_lock(char* path)
 {
@@ -66,6 +66,8 @@ dot_lock(char* path)
 
        raise_gid();
        for (i = 0; i < LOCK_MAX_TRIES; i++){
+               struct stat buf;
+
                if ((fd = open(lockfile, O_WRONLY | O_EXCL | O_CREAT, 0)) 
                        >= 0) {
                        close(fd);
@@ -75,8 +77,10 @@ dot_lock(char* path)
 
                if (errno != EEXIST)
                        break;
-
-               /* FIXME: deal with old locks */
+               /* deal with old locks */
+               stat(lockfile, &buf);
+               if ((time(NULL) - buf.st_mtime) > 3600)
+                       unlink(lockfile);               
                random_sleep(1, 1);
        }
        drop_gid();