From c1355e1fb481abbb1dba9f8d5229960252b2d43f Mon Sep 17 00:00:00 2001 From: Gerd Moellmann Date: Fri, 14 Apr 2000 13:03:20 +0000 Subject: [PATCH] (MAKE_LOCK_NAME): Allocate 2 more bytes. (fill_in_lock_file_name): Avoid existing files that aren't links. --- src/filelock.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/filelock.c b/src/filelock.c index 8fb41a3d7eb..02b3ccc8b05 100644 --- a/src/filelock.c +++ b/src/filelock.c @@ -311,9 +311,11 @@ 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 one for the null. */ + 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 + null. */ #define MAKE_LOCK_NAME(lock, file) \ - (lock = (char *) alloca (STRING_BYTES (XSTRING (file)) + 2 + 1), \ + (lock = (char *) alloca (STRING_BYTES (XSTRING (file)) + 2 + 1 + 1 + 1), \ fill_in_lock_file_name (lock, (file))) static void @@ -322,6 +324,8 @@ fill_in_lock_file_name (lockfile, fn) register Lisp_Object fn; { register char *p; + struct stat st; + int count = 0; strcpy (lockfile, XSTRING (fn)->data); @@ -334,6 +338,18 @@ fill_in_lock_file_name (lockfile, fn) /* Insert the `.#'. */ p[1] = '.'; p[2] = '#'; + + p = p + strlen (p); + + 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. -- 2.39.5