Subject: Re: bug#29955: 25.2; stale lock files can hang emacs --batch
From: Glenn Morris <[email-masked]>
To: [email-masked]
Date: Tue, 23 Jan 2018 20:59:37 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

Version: 27.1

I applied the following to master (though emacs-26 seems appropriate to me).
Together with 28718c4, it should fix this issue.

commit 109da68
Date:   Tue Jan 23 20:55:09 2018 -0500

    Avoid kill-emacs-hook errors hanging batch mode
    
    * src/emacs.c (Fkill_emacs): Prevent errors from kill-emacs-hook
    hanging Emacs in batch mode.  (Bug#29955)

diff --git a/src/emacs.c b/src/emacs.c
index 84cd3ac..8ea61b7 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -2024,7 +2024,10 @@ all of which are called before Emacs is actually killed.  */
   /* Fsignal calls emacs_abort () if it sees that waiting_for_input is
      set.  */
   waiting_for_input = 0;
-  run_hook (Qkill_emacs_hook);
+  if (noninteractive)
+    safe_run_hooks (Qkill_emacs_hook);
+  else
+    run_hook (Qkill_emacs_hook);
 
 #ifdef HAVE_X_WINDOWS
   /* Transfer any clipboards we own to the clipboard manager.  */