emacs-devel
[Top][All Lists]
Advanced

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

Re: Bug in filelock.c


From: Paul Eggert
Subject: Re: Bug in filelock.c
Date: Sat, 23 Feb 2013 11:39:43 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2

On 02/23/2013 11:07 AM, Eli Zaretskii wrote:
> Am I missing something?

No, it looks like a clear bug.  Thanks for catching it!

Also, that "p != lockfile" business is bogus;
p can never equal lockfile.

Since the code has obviously never worked and evidently
never been needed and slows Emacs down with unnecessary
syscalls, I propose that we remove it, as follows:

=== modified file 'src/filelock.c'
--- src/filelock.c      2013-02-01 06:30:51 +0000
+++ src/filelock.c      2013-02-23 19:37:31 +0000
@@ -289,44 +289,31 @@ typedef struct
 
 
 /* Write the name of the lock file for FN into LFNAME.  Length will be
-   that of FN plus two more for the leading `.#' plus 1 for the
-   trailing period plus one for the digit after it plus one for the
+   that of FN plus two more for the leading `.#' plus one for the
    null.  */
 #define MAKE_LOCK_NAME(lock, file) \
-  (lock = alloca (SBYTES (file) + 2 + 1 + 1 + 1), \
+  (lock = alloca (SBYTES (file) + 2 + 1), \
    fill_in_lock_file_name (lock, (file)))
 
 static void
 fill_in_lock_file_name (register char *lockfile, register Lisp_Object fn)
 {
   ptrdiff_t length = SBYTES (fn);
-  register char *p;
-  struct stat st;
-  int count = 0;
+  char *p;
 
   strcpy (lockfile, SSDATA (fn));
 
   /* Shift the nondirectory part of the file name (including the null)
      right two characters.  Here is one of the places where we'd have to
      do something to support 14-character-max file names.  */
-  for (p = lockfile + length; p != lockfile && *p != '/'; p--)
+  p = lockfile + length;
+  do
     p[2] = *p;
+  while (*--p != '/');
 
   /* Insert the `.#'.  */
   p[1] = '.';
   p[2] = '#';
-
-  p = p + length + 2;
-
-  while (lstat (lockfile, &st) == 0 && !S_ISLNK (st.st_mode))
-    {
-      if (count > 9)
-       {
-         *p = '\0';
-         return;
-       }
-      sprintf (p, ".%d", count++);
-    }
 }
 
 /* Lock the lock file named LFNAME.





reply via email to

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