From 6207bdbcb81fbacb19da0d779fe664bad213a7d2 Mon Sep 17 00:00:00 2001 From: Anicka Bernathova Date: Fri, 17 Jul 2009 12:22:44 +0200 Subject: [PATCH] cope with old locks --- lock.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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(); -- 2.39.2