emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lib-src/update-game-score.c


From: Colin Walters
Subject: [Emacs-diffs] Changes to emacs/lib-src/update-game-score.c
Date: Sun, 14 Apr 2002 02:40:19 -0400

Index: emacs/lib-src/update-game-score.c
diff -c emacs/lib-src/update-game-score.c:1.6 
emacs/lib-src/update-game-score.c:1.7
*** emacs/lib-src/update-game-score.c:1.6       Sat Apr 13 21:02:36 2002
--- emacs/lib-src/update-game-score.c   Sun Apr 14 02:40:19 2002
***************
*** 416,421 ****
--- 416,422 ----
  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,431 ****
--- 427,436 ----
    *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,439 ****
          /* Break the lock; we won't corrupt the file, but we might
             lose some scores. */
          if (attempts > MAX_ATTEMPTS)
!           unlink(lockpath);
          sleep((rand() % 2)+1);
          goto trylock;
        }
--- 438,447 ----
          /* Break the lock; we won't corrupt the file, but we might
             lose some scores. */
          if (attempts > MAX_ATTEMPTS)
!           {
!             unlink(lockpath);
!             attempts = 0;
!           }
          sleep((rand() % 2)+1);
          goto trylock;
        }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]