From: Eli Zaretskii Date: Sat, 4 May 2024 10:12:21 +0000 (+0300) Subject: Fix implementation of the --terminal command-line switch X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a2bd806fe4f02ede629e2579beef7e04b157b987;p=emacs.git Fix implementation of the --terminal command-line switch 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) --- diff --git a/src/emacs.c b/src/emacs.c index 7431cef274d..77e6c41e822 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -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 diff --git a/src/keyboard.c b/src/keyboard.c index a06c9116d24..69d29ededc0 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -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) diff --git a/src/keyboard.h b/src/keyboard.h index 2ce003fd444..42637ca1cf7 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -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 diff --git a/src/process.c b/src/process.c index 6b8b483cdf7..50d1968200d 100644 --- a/src/process.c +++ b/src/process.c @@ -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); diff --git a/src/term.c b/src/term.c index 6cb57592643..903444ef69f 100644 --- a/src/term.c +++ b/src/term.c @@ -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