]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix implementation of the --terminal command-line switch
authorEli Zaretskii <eliz@gnu.org>
Sat, 4 May 2024 10:12:21 +0000 (13:12 +0300)
committerEshel Yaron <me@eshelyaron.com>
Mon, 6 May 2024 16:38:35 +0000 (18:38 +0200)
It sounds like this has been broken ever since multi-tty was
added to Emacs.
* src/keyboard.c (dev_tty): New global variable.
* src/keyboard.h: Declare 'dev_tty'.
* src/emacs.c (main): Initialize 'dev_tty'.
* src/term.c (Fcontrolling_tty_p, Fresume_tty, init_tty):
* src/process.c (dissociate_controlling_tty):
* src/keyboard.c (handle_interrupt_signal, handle_interrupt)
(Fset_quit_char): Use 'dev_tty' instead of 'DEV_TTY'.  (Bug#70519)

(cherry picked from commit fa0f65aa342e181e0e98f55cbf5d9a9be5ed3be6)

src/emacs.c
src/keyboard.c
src/keyboard.h
src/process.c
src/term.c

index 7431cef274d8786a4c09bc0cc3b955ac1b9d55ef..77e6c41e8220af6eda0f36cca2145da97fd83d65 100644 (file)
@@ -1653,6 +1653,7 @@ main (int argc, char **argv)
   inhibit_window_system = 0;
 
   /* Handle the -t switch, which specifies filename to use as terminal.  */
+  dev_tty = xstrdup (DEV_TTY); /* the default terminal */
   while (!only_version)
     {
       char *term;
@@ -1675,6 +1676,8 @@ main (int argc, char **argv)
              exit (EXIT_FAILURE);
            }
          fprintf (stderr, "Using %s\n", term);
+         xfree (dev_tty);
+         dev_tty = xstrdup (term);
 #ifdef HAVE_WINDOW_SYSTEM
          inhibit_window_system = true; /* -t => -nw */
 #endif
index a06c9116d244e5d8391db401336e67eb9322569d..69d29ededc08db8b5f6661482b988b015f99367c 100644 (file)
@@ -98,6 +98,7 @@ char const DEV_TTY[] = "CONOUT$";
 #else
 char const DEV_TTY[] = "/dev/tty";
 #endif
+char *dev_tty; /* set by init_keyboard */
 
 /* Variables for blockinput.h:  */
 
@@ -12003,7 +12004,7 @@ static void
 handle_interrupt_signal (int sig)
 {
   /* See if we have an active terminal on our controlling tty.  */
-  struct terminal *terminal = get_named_terminal (DEV_TTY);
+  struct terminal *terminal = get_named_terminal (dev_tty);
   if (!terminal)
     {
       /* If there are no frames there, let's pretend that we are a
@@ -12072,7 +12073,7 @@ handle_interrupt (bool in_signal_handler)
   cancel_echoing ();
 
   /* XXX This code needs to be revised for multi-tty support.  */
-  if (!NILP (Vquit_flag) && get_named_terminal (DEV_TTY))
+  if (!NILP (Vquit_flag) && get_named_terminal (dev_tty))
     {
       if (! in_signal_handler)
        {
@@ -12365,7 +12366,7 @@ process.
 See also `current-input-mode'.  */)
   (Lisp_Object quit)
 {
-  struct terminal *t = get_named_terminal (DEV_TTY);
+  struct terminal *t = get_named_terminal (dev_tty);
   struct tty_display_info *tty;
 
   if (!t)
index 2ce003fd444b504576369dc745682e7c292d4903..42637ca1cf78684473e1ffa19a0f80696bf74e14 100644 (file)
@@ -521,6 +521,9 @@ extern void mark_kboards (void);
 extern const char *const lispy_function_keys[];
 #endif
 
+/* Terminal device used by Emacs for terminal I/O.  */
+extern char *dev_tty;
+/* Initial value for dev_tty.  */
 extern char const DEV_TTY[];
 
 INLINE_HEADER_END
index 6b8b483cdf7ca88db861151363f3090b0fe3a764..50d1968200da12d32e4d8116ca465bd930507d79 100644 (file)
@@ -2114,7 +2114,7 @@ dissociate_controlling_tty (void)
         child that has not execed.
         I wonder: would just ioctl (fd, TIOCNOTTY, 0) work here, for
         some fd that the caller already has?  */
-      int ttyfd = emacs_open (DEV_TTY, O_RDWR, 0);
+      int ttyfd = emacs_open (dev_tty, O_RDWR, 0);
       if (0 <= ttyfd)
        {
          ioctl (ttyfd, TIOCNOTTY, 0);
index 6cb57592643c76cc1e7f10cb988c488329fe1d53..903444ef69f36b71b04b653c320643bdba2b4103 100644 (file)
@@ -2312,7 +2312,7 @@ TERMINAL is not on a tty device.  */)
 {
   struct terminal *t = decode_tty_terminal (terminal);
 
-  return (t && !strcmp (t->display_info.tty->name, DEV_TTY) ? Qt : Qnil);
+  return (t && !strcmp (t->display_info.tty->name, dev_tty) ? Qt : Qnil);
 }
 
 DEFUN ("tty-no-underline", Ftty_no_underline, Stty_no_underline, 0, 1, 0,
@@ -2467,7 +2467,7 @@ frame's terminal). */)
                             open_errno);
        }
 
-      if (!O_IGNORE_CTTY && strcmp (t->display_info.tty->name, DEV_TTY) != 0)
+      if (!O_IGNORE_CTTY && strcmp (t->display_info.tty->name, dev_tty) != 0)
         dissociate_if_controlling_tty (fd);
 #endif /* MSDOS */
 
@@ -4075,7 +4075,7 @@ dissociate_if_controlling_tty (int fd)
 /* Create a termcap display on the tty device with the given name and
    type.
 
-   If NAME is NULL, then use the controlling tty, i.e., DEV_TTY.
+   If NAME is NULL, then use the controlling tty, i.e., dev_tty.
    Otherwise NAME should be a path to the tty device file,
    e.g. "/dev/pts/7".
 
@@ -4114,9 +4114,9 @@ init_tty (const char *name, const char *terminal_type, bool must_succeed)
                  "Unknown terminal type");
 
   if (name == NULL)
-    name = DEV_TTY;
+    name = dev_tty;
 #ifndef DOS_NT
-  if (!strcmp (name, DEV_TTY))
+  if (!strcmp (name, dev_tty))
     ctty = 1;
 #endif