Subject: bug#78583: 31.0.50; emacs --fg-daemon not protecting frame F1

From: martin rudalics <[email-masked]>
Date: Tue, 27 May 2025 18:28:39 +0200

> On another note, I still believe that in daemonized emacs the F1 frame
 > is special and should never be deleted by regular frame commands, (it
 > should still be possible, but only after warning and user
 > confirmation).  Would you agree? or perhaps you can suggest how best
 > this may be done. --Best Regards, Madhu

I can offer the below.  It would have to be documented somewhere in the
daemon/emacsclient section.  After all (delete-frame terminal-frame) can
be used to kill the daemon - I never use emacsclient so I have no idea
whether and how useful that would be.

martin

diff --git a/src/frame.c b/src/frame.c
index f2acb19c77d..7a07f538d9f 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -2481,6 +2481,8 @@ delete_frame (Lisp_Object frame, Lisp_Object force)
        else
  	error ("Attempt to delete the only frame");
      }
+  else if (IS_DAEMON && FRAME_INITIAL_P (f) && NILP (force))
+    error ("Attempt to delete daemon's initial frame");
  #ifdef HAVE_X_WINDOWS
    else if ((x_dnd_in_progress && f == x_dnd_frame)
  	   || (x_dnd_waiting_for_finish && f == x_dnd_finish_frame))