aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1996-09-12 17:29:17 +0000
committerRichard M. Stallman1996-09-12 17:29:17 +0000
commita1faca26314b34b592f391baa5bc4d014bc1ef2c (patch)
tree39d95c1b5b9d187484d62337beb9a57d3e40b43e /src
parent9614b740acd2fb94fc91a63ed57778fa1647281e (diff)
downloademacs-a1faca26314b34b592f391baa5bc4d014bc1ef2c.tar.gz
emacs-a1faca26314b34b592f391baa5bc4d014bc1ef2c.zip
(lock_superlock): Delete superlock file if it stayed
locked for 20 seconds.
Diffstat (limited to 'src')
-rw-r--r--src/filelock.c54
1 files changed, 43 insertions, 11 deletions
diff --git a/src/filelock.c b/src/filelock.c
index 5393867063c..6c1b6b2a1c4 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -353,32 +353,64 @@ lock_superlock (lfname)
353{ 353{
354 register int i, fd; 354 register int i, fd;
355 DIR *lockdir; 355 DIR *lockdir;
356 struct stat first_stat, last_stat;
356 357
357 for (i = -20; i < 0 && (fd = open (superlock_file, 358 for (i = -20; i < 0;
358 O_WRONLY | O_EXCL | O_CREAT, 0666)) < 0;
359 i++) 359 i++)
360 { 360 {
361 fd = open (superlock_file,
362 O_WRONLY | O_EXCL | O_CREAT, 0666);
363
364 /* If we succeeded in creating the superlock, we win.
365 Fill in our info and return. */
366 if (fd >= 0)
367 {
368#ifdef USG
369 chmod (superlock_file, 0666);
370#else
371 fchmod (fd, 0666);
372#endif
373 write (fd, lfname, strlen (lfname));
374 close (fd);
375 return;
376 }
377
378 /* If the problem is not just that it is already locked,
379 give up. */
361 if (errno != EEXIST) 380 if (errno != EEXIST)
362 return; 381 return;
363 382
383 message ("Superlock file exists, retrying...");
384
385 if (i == -20)
386 stat (superlock_file, &first_stat);
387
388 if (i == -1)
389 stat (superlock_file, &last_stat);
390
364 /* This seems to be necessary to prevent Emacs from hanging when the 391 /* This seems to be necessary to prevent Emacs from hanging when the
365 competing process has already deleted the superlock, but it's still 392 competing process has already deleted the superlock, but it's still
366 in the NFS cache. So we force NFS to synchronize the cache. */ 393 in the NFS cache. So we force NFS to synchronize the cache. */
367 if (lockdir = opendir (lock_dir)) 394 lockdir = opendir (lock_dir);
395
396 if (lockdir)
368 closedir (lockdir); 397 closedir (lockdir);
369 398
370 sleep (1); 399 sleep (1);
371 } 400 }
372 if (fd >= 0) 401
402 if (first_stat.st_ctime == last_stat.st_ctime)
373 { 403 {
374#ifdef USG 404 int value;
375 chmod (superlock_file, 0666); 405 value = unlink (superlock_file);
376#else 406
377 fchmod (fd, 0666); 407 if (value != -1)
378#endif 408 message ("Superlock file deleted");
379 write (fd, lfname, strlen (lfname)); 409 else
380 close (fd); 410 message ("Failed to delete superlock file");
381 } 411 }
412 else
413 message ("Giving up on the superlock file");
382} 414}
383 415
384void 416void