aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2015-05-08 12:20:16 +0300
committerEli Zaretskii2015-05-08 12:20:16 +0300
commit25fde89819f9b782646ee4edd2f32d382ef1b2b1 (patch)
treefd2e318fe9cf5f54c7e9b11e0a73fbd27a629071
parent0d0a4d06efff115f35b4813fa7d2d68b2c600297 (diff)
downloademacs-25fde89819f9b782646ee4edd2f32d382ef1b2b1.tar.gz
emacs-25fde89819f9b782646ee4edd2f32d382ef1b2b1.zip
Verify file modifications by other programs
* src/filelock.c (lock_file): Check whether the file was modified since it was visited even if 'create-lockfiles' is nil. (Bug#18828)
-rw-r--r--src/filelock.c49
1 files changed, 25 insertions, 24 deletions
diff --git a/src/filelock.c b/src/filelock.c
index 89d3e350219..4ee7a01ecb8 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -669,10 +669,6 @@ lock_file (Lisp_Object fn)
669 struct gcpro gcpro1; 669 struct gcpro gcpro1;
670 USE_SAFE_ALLOCA; 670 USE_SAFE_ALLOCA;
671 671
672 /* Don't do locking if the user has opted out. */
673 if (! create_lockfiles)
674 return;
675
676 /* Don't do locking while dumping Emacs. 672 /* Don't do locking while dumping Emacs.
677 Uncompressing wtmp files uses call-process, which does not work 673 Uncompressing wtmp files uses call-process, which does not work
678 in an uninitialized Emacs. */ 674 in an uninitialized Emacs. */
@@ -690,9 +686,6 @@ lock_file (Lisp_Object fn)
690#endif 686#endif
691 encoded_fn = ENCODE_FILE (fn); 687 encoded_fn = ENCODE_FILE (fn);
692 688
693 /* Create the name of the lock-file for file fn */
694 MAKE_LOCK_NAME (lfname, encoded_fn);
695
696 /* See if this file is visited and has changed on disk since it was 689 /* See if this file is visited and has changed on disk since it was
697 visited. */ 690 visited. */
698 { 691 {
@@ -707,27 +700,35 @@ lock_file (Lisp_Object fn)
707 700
708 } 701 }
709 702
710 /* Try to lock the lock. */ 703 /* Don't do locking if the user has opted out. */
711 if (0 < lock_if_free (&lock_info, lfname)) 704 if (create_lockfiles)
712 { 705 {
713 /* Someone else has the lock. Consider breaking it. */ 706
714 Lisp_Object attack; 707 /* Create the name of the lock-file for file fn */
715 char *dot = lock_info.dot; 708 MAKE_LOCK_NAME (lfname, encoded_fn);
716 ptrdiff_t pidlen = lock_info.colon - (dot + 1); 709
717 static char const replacement[] = " (pid "; 710 /* Try to lock the lock. */
718 int replacementlen = sizeof replacement - 1; 711 if (0 < lock_if_free (&lock_info, lfname))
719 memmove (dot + replacementlen, dot + 1, pidlen); 712 {
720 strcpy (dot + replacementlen + pidlen, ")"); 713 /* Someone else has the lock. Consider breaking it. */
721 memcpy (dot, replacement, replacementlen); 714 Lisp_Object attack;
722 attack = call2 (intern ("ask-user-about-lock"), fn, 715 char *dot = lock_info.dot;
723 build_string (lock_info.user)); 716 ptrdiff_t pidlen = lock_info.colon - (dot + 1);
724 /* Take the lock if the user said so. */ 717 static char const replacement[] = " (pid ";
725 if (!NILP (attack)) 718 int replacementlen = sizeof replacement - 1;
726 lock_file_1 (lfname, 1); 719 memmove (dot + replacementlen, dot + 1, pidlen);
720 strcpy (dot + replacementlen + pidlen, ")");
721 memcpy (dot, replacement, replacementlen);
722 attack = call2 (intern ("ask-user-about-lock"), fn,
723 build_string (lock_info.user));
724 /* Take the lock if the user said so. */
725 if (!NILP (attack))
726 lock_file_1 (lfname, 1);
727 }
728 SAFE_FREE ();
727 } 729 }
728 730
729 UNGCPRO; 731 UNGCPRO;
730 SAFE_FREE ();
731} 732}
732 733
733void 734void