From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Matt Armstrong Newsgroups: gmane.emacs.bugs Subject: bug#46397: 27.1; Cannot delete buffer pointing to a file in a path that includes a file Date: Thu, 11 Feb 2021 14:14:52 -0800 Message-ID: References: <87h7mllgin.fsf@nexoid.at> <83a6scj745.fsf@gnu.org> <39d0e035-27b6-e2bd-daa2-747dda2c1a35@cs.ucla.edu> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24258"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 46397@debbugs.gnu.org, craven@gmx.net To: Paul Eggert , Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Feb 11 23:16:49 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lAKGX-0006Bx-6z for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 11 Feb 2021 23:16:49 +0100 Original-Received: from localhost ([::1]:43626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lAKGW-0003yi-9E for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 11 Feb 2021 17:16:48 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAKFm-0003Ym-HE for bug-gnu-emacs@gnu.org; Thu, 11 Feb 2021 17:16:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47952) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lAKFm-0002xa-9E for bug-gnu-emacs@gnu.org; Thu, 11 Feb 2021 17:16:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lAKFm-0008BL-4d for bug-gnu-emacs@gnu.org; Thu, 11 Feb 2021 17:16:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Matt Armstrong Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 11 Feb 2021 22:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46397 X-GNU-PR-Package: emacs Original-Received: via spool by 46397-submit@debbugs.gnu.org id=B46397.161308170731386 (code B ref 46397); Thu, 11 Feb 2021 22:16:02 +0000 Original-Received: (at 46397) by debbugs.gnu.org; 11 Feb 2021 22:15:07 +0000 Original-Received: from localhost ([127.0.0.1]:59498 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lAKEt-0008A9-Er for submit@debbugs.gnu.org; Thu, 11 Feb 2021 17:15:07 -0500 Original-Received: from relay1-d.mail.gandi.net ([217.70.183.193]:57297) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lAKEq-00089K-7d for 46397@debbugs.gnu.org; Thu, 11 Feb 2021 17:15:05 -0500 X-Originating-IP: 24.113.169.116 Original-Received: from matts-mbp-2016.lan (24-113-169-116.wavecable.com [24.113.169.116]) (Authenticated sender: matt@rfc20.org) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 115D1240002; Thu, 11 Feb 2021 22:14:55 +0000 (UTC) In-Reply-To: <39d0e035-27b6-e2bd-daa2-747dda2c1a35@cs.ucla.edu> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:199832 Archived-At: Paul Eggert writes: > The second bug is that once you're in a tricky situation where the file > can't be unlocked for whatever reason and you attempt to exit Emacs, > Emacs tries to auto-save the buffer, fails because of the lock problem, > and then gets into a weird state where you cannot do anything. This > problem can happen in other scenarios. For example: > > * Run Emacs and visit the file /tmp/a/b where /tmp/a does not exist. > Emacs will warn "Use M-x make-directory RET RET to create the directory > and its parents"; ignore the warning. > > * Type some characters so that /tmp/a/b's buffer is nonempty. > > * Create an inaccessible directory /tmp/a by running "mkdir -m 0 /tmp/a" > outside Emacs. > > * Type C-x C-c to exit Emacs. It will say "Save file /tmp/a/b?" Type > "n". It will then say "Modified buffers exist; exit anyway? (yes or > no)". Type "yes". Emacs will then hang, in a weird state where it is > trying to auto-save but hanging in the middle of that. > > I did not fix this latter problem, so it needs further investigation. Paul, I looked into this second issue a bit. The issue isn't confined to exiting Emacs. It appears that once in a "tricky situation where the file can't be unlocked for whatever reason" Emacs will refuse to kill the buffer because unlock_file() signals an error. The problem is more severe when exiting Emacs because it occurs after Emacs is in a half shut down state. The shutdown sequence does not take kindly to the unhandled non-local exit. I used this for a quick repro: (cl-flet ((command-in-tmp (prog &rest args) (with-temp-buffer (cd-absolute "/tmp") (apply #'call-process prog nil nil nil args)))) (command-in-tmp "chmod" "u+rwx" "a") (command-in-tmp "rm" "-rf" "a") (find-file "/tmp/a/b") (insert "Hello, World!") (command-in-tmp "mkdir" "-m" "0" "a")) At shutdown, the following call stack signals an error: kill_emacs -> shut_down_emacs -> unlock_all_files -> unlock_file -> report_file_errno In this case, the errno is "permission denied." Note that shut_down_emacs() calls Fdo_auto_save() just before unlock_all_files() and that call succeeds. Fdo_auto_save() also calls report_file_errno, throwing an errno 13 (Permission denied), but that recovers and continues.