#include <fcntl.h>
#include <errno.h>
#include <sys/stat.h>
+#include <time.h>
#include "umpf.h"
return res;
}
-/* FIXME: what about privileges? */
static int
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);
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();