# HG changeset patch # User Colin Walters # Date 1018766419 0 # Node ID 90866353c7bdcf7634117258ccb5b155692e7a1b # Parent 52bd3d1b9cb9e71541b6e74ec7e20724fd4fb15a (lock_file): If the lock file is older than an hour, delete it. Reset attempts to zero if we have to break the lock. diff -r 52bd3d1b9cb9 -r 90866353c7bd lib-src/update-game-score.c --- a/lib-src/update-game-score.c Sun Apr 14 05:51:31 2002 +0000 +++ b/lib-src/update-game-score.c Sun Apr 14 06:40:19 2002 +0000 @@ -416,6 +416,7 @@ lock_file(const char *filename, void **state) { int fd; + struct stat buf; int attempts = 0; char *lockext = ".lockfile"; char *lockpath = malloc(strlen(filename) + strlen(lockext) + 60); @@ -426,6 +427,10 @@ *state = lockpath; trylock: attempts++; + /* If the lock is over an hour old, delete it. */ + if (stat(lockpath, &buf) == 0 + && (difftime(buf.st_ctime, time(NULL) > 60*60))) + unlink(lockpath); if ((fd = open(lockpath, O_CREAT | O_EXCL, 0600)) < 0) { if (errno == EEXIST) @@ -433,7 +438,10 @@ /* Break the lock; we won't corrupt the file, but we might lose some scores. */ if (attempts > MAX_ATTEMPTS) - unlink(lockpath); + { + unlink(lockpath); + attempts = 0; + } sleep((rand() % 2)+1); goto trylock; }