Subject: Re: bug#56800: Pointless "Warning: desktop file appears to be in use by PID ###."

From: Paul Pogonyshev <[email-masked]>
Date: Wed, 27 Jul 2022 21:22:46 +0200

I meant something like what is in the attached patch. The problem is that
_everything_ got moved to `...-query-functions', including that part that
has nothing to do with querying.

Paul

On Wed, 27 Jul 2022 at 20:58, Eli Zaretskii <[email-masked]> wrote:

> > From: Paul Pogonyshev <[email-masked]>
> > Date: Wed, 27 Jul 2022 19:52:31 +0200
> > Cc: [email-masked]
> >
> > Yeah, apparently `kill-emacs' is considered "low-level primitive":
> >
> >     Functions to call with no arguments to query about killing Emacs.
> >     If any of these functions returns nil, killing Emacs is canceled.
> >     ‘save-buffers-kill-emacs’ calls these functions, but ‘kill-emacs’,
> >     the low level primitive, does not.  See also ‘kill-emacs-hook’.
> >
> > Since I have rebound C-x C-c for my private use (why waste such a nice
> shortcut on something used once
> > in a few days?), I have been using `kill-emacs'. But apparently it's not
> what should be used... Emacs making
> > it easy to silently break things, nothing new.
> >
> > I suggest that `desktop-release-lock' call is still moved from something
> hooked on
> > `kill-emacs-query-functions' to `kill-emacs-hook'. That part is supposed
> to be done unconditionally.
>
> That change was made because the hook can ask questions, which doesn't
> work in a daemon session.  So we moved the hook.
>
From e738c06312ce32f92acd62cdad9d8342451bd734 Mon Sep 17 00:00:00 2001
From: Paul Pogonyshev <[email-masked]>
Date: Wed, 27 Jul 2022 21:20:55 +0200
Subject: [PATCH] Followup to 5bd04ea307: still have `M-x kill-emacs' release
 desktop lock

---
 lisp/desktop.el | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lisp/desktop.el b/lisp/desktop.el
index 850d2a86ef..a0931e053e 100644
--- a/lisp/desktop.el
+++ b/lisp/desktop.el
@@ -791,7 +791,10 @@ desktop-clear
 
 ;; ----------------------------------------------------------------------------
 (unless noninteractive
-  (add-hook 'kill-emacs-query-functions #'desktop-kill))
+  (add-hook 'kill-emacs-query-functions #'desktop-kill)
+  ;; Certain things should be done even if
+  ;; `kill-emacs-query-functions' are not called.
+  (add-hook 'kill-emacs-hook #'desktop--on-kill))
 
 (defun desktop-kill ()
   "If `desktop-save-mode' is non-nil, do what `desktop-save' says to do.
@@ -818,12 +821,15 @@ desktop-kill
       (file-error
        (unless (yes-or-no-p "Error while saving the desktop.  Ignore? ")
 	 (signal (car err) (cdr err))))))
+  (desktop--on-kill)
+  t)
+
+(defun desktop--on-kill ()
   ;; If we own it, we don't anymore.
   (when (eq (emacs-pid) (desktop-owner))
     ;; Allow exiting Emacs even if we can't delete the desktop file.
     (ignore-error 'file-error
-      (desktop-release-lock)))
-  t)
+      (desktop-release-lock))))
 
 ;; ----------------------------------------------------------------------------
 (defun desktop-list* (&rest args)
-- 
2.35.1