From 8b36bfc553b97cf435bdfe1b84abe21c3a605b9f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 15 Aug 2024 13:30:23 -0700 Subject: [PATCH 4/4] Remove empty (& invalid) lock files * src/filelock.c (current_lock_owner): Remove empty lock files, as they are necessarily invalid and can be caused by buggy file systems. Problem reported by Michal Nazarewicz (bug#72641). --- src/filelock.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/filelock.c b/src/filelock.c index c68aacc46fb..1ae57dc7344 100644 --- a/src/filelock.c +++ b/src/filelock.c @@ -397,8 +397,8 @@ current_lock_owner (lock_info_type *owner, Lisp_Object lfname) if (lfinfolen < 0) return errno == ENOENT || errno == ENOTDIR ? 0 : errno; - /* Examine lock file contents. */ - if (true) + /* If the lock file seems valid, return a value based on its contents. */ + if (lfinfolen) { if (MAX_LFINFO < lfinfolen) return ENAMETOOLONG; @@ -496,8 +496,11 @@ current_lock_owner (lock_info_type *owner, Lisp_Object lfname) return ANOTHER_OWNS_IT; } - /* The owner process is dead or has a strange pid. - Try to zap the lockfile. */ + /* The owner process is dead or has a strange pid, or the lock file is empty. + Try to zap the lockfile. If the lock file is empty, this assumes + the file system is buggy, e.g., . + Emacs never creates empty lock files even temporarily, so removing + an empty lock file should be harmless. */ return emacs_unlink (SSDATA (lfname)) < 0 ? errno : 0; } -- 2.43.0