From: Paul Eggert Date: Sun, 17 Apr 2022 08:44:30 +0000 (-0700) Subject: Merge from origin/emacs-28 X-Git-Tag: emacs-29.0.90~1931^2~476 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ff7bc018307681564235583722675997dc309915;p=emacs.git Merge from origin/emacs-28 4641bc1c55 Fix GC bug in filelock.c --- ff7bc018307681564235583722675997dc309915 diff --cc src/filelock.c index 4fdad8d8560,25b35feb02b..8fa86e64eb8 --- a/src/filelock.c +++ b/src/filelock.c @@@ -511,8 -495,9 +510,8 @@@ enu or an errno value if something is wrong with the locking mechanism. */ static int - current_lock_owner (lock_info_type *owner, char *lfname) + current_lock_owner (lock_info_type *owner, Lisp_Object lfname) { - int ret; lock_info_type local_owner; ptrdiff_t lfinfolen; intmax_t pid, boot_time; @@@ -612,12 -594,12 +611,12 @@@ /* Lock the lock named LFNAME if possible. Return 0 in that case. - Return negative if some other process owns the lock, and info about + Return ANOTHER_OWNS_IT if some other process owns the lock, and info about that process in CLASHER. - Return positive errno value if cannot lock for any other reason. */ + Return errno value if cannot lock for any other reason. */ static int - lock_if_free (lock_info_type *clasher, char *lfname) + lock_if_free (lock_info_type *clasher, Lisp_Object lfname) { int err; while ((err = lock_file_1 (lfname, 0)) == EEXIST) @@@ -687,15 -672,15 +689,15 @@@ lock_file (Lisp_Object fn if (!NILP (subject_buf) && NILP (Fverify_visited_file_modtime (subject_buf)) && !NILP (Ffile_exists_p (fn)) - && !(lfname && (current_lock_owner (NULL, lfname) == I_OWN_IT))) - && !(!NILP (lfname) && current_lock_owner (NULL, lfname) == -2)) ++ && !(!NILP (lfname) && current_lock_owner (NULL, lfname) == I_OWN_IT)) call1 (intern ("userlock--ask-user-about-supersession-threat"), fn); /* Don't do locking if the user has opted out. */ - if (lfname) + if (!NILP (lfname)) { /* Try to lock the lock. FIXME: This ignores errors when -- lock_if_free returns a positive errno value. */ - if (lock_if_free (&lock_info, lfname) < 0) ++ lock_if_free returns an errno value. */ + if (lock_if_free (&lock_info, lfname) == ANOTHER_OWNS_IT) { /* Someone else has the lock. Consider breaking it. */ Lisp_Object attack; @@@ -719,17 -704,14 +721,14 @@@ static Lisp_Object unlock_file (Lisp_Object fn) { - char *lfname; - - Lisp_Object lock_filename = make_lock_file_name (fn); - if (NILP (lock_filename)) + Lisp_Object lfname = make_lock_file_name (fn); + if (NILP (lfname)) return Qnil; - lfname = SSDATA (ENCODE_FILE (lock_filename)); int err = current_lock_owner (0, lfname); - if (err == -2 && unlink (SSDATA (lfname)) != 0 && errno != ENOENT) - err = errno; - if (0 < err) + if (! (err == 0 || err == ANOTHER_OWNS_IT + || (err == I_OWN_IT - && (unlink (lfname) == 0 || (err = errno) == ENOENT)))) ++ && (unlink (SSDATA (lfname)) == 0 || (err = errno) == ENOENT)))) report_file_errno ("Unlocking file", fn, err); return Qnil;