From: Anicka Bernathova Date: Fri, 17 Jul 2009 10:22:44 +0000 (+0200) Subject: cope with old locks X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=6207bdbcb81fbacb19da0d779fe664bad213a7d2;p=umpf.git cope with old locks --- diff --git a/lock.c b/lock.c index 5aa6a7a..12f4083 100644 --- a/lock.c +++ b/lock.c @@ -8,6 +8,7 @@ #include #include #include +#include #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();