Subject: 30.0.50; Device for Emacs terminal I/O

From: Helmut Eller <[email-masked]>
Date: Mon, 22 Apr 2024 22:09:18 +0200

I'd like to start Emacs under GDB, but so that Emacs doesn't use the
same terminal as GDB.  It seems that the --terminal command line switch
is there for exactly this use case.

However, it doesn't work.  Emacs parses the command line option and
replaces stdin and stdout with the correct device, but then in dispnew.c
it always calls init_tty with 0 as argument for the device name.  That
simply opens the controlling terminal, i.e. /dev/tty and that is usually
the same device as the one that GDB uses.

What would you think of the change below?

Helmut

diff --git a/src/dispnew.c b/src/dispnew.c
index 0f5063c047f..cc5b883c138 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -6710,7 +6710,8 @@ init_display_interactive (void)
     init_foreground_group ();
 
     /* Open a display on the controlling tty. */
-    t = init_tty (0, terminal_type, 1); /* Errors are fatal. */
+    /* Errors are fatal. */
+    t = init_tty (ttyname (STDIN_FILENO), terminal_type, 1);
 
     /* Convert the initial frame to use the new display. */
     if (f->output_method != output_initial)