GNU bug report logs - #70519
30.0.50; Device for Emacs terminal I/O

Previous Next

Package: emacs;

Reported by: Helmut Eller <eller.helmut <at> gmail.com>

Date: Mon, 22 Apr 2024 20:10:04 UTC

Severity: normal

Found in version 30.0.50

Full log


Message #32 received at 70519 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 70519 <at> debbugs.gnu.org, eller.helmut <at> gmail.com
Subject: Re: bug#70519: 30.0.50; Device for Emacs terminal I/O
Date: Sat, 04 May 2024 20:19:38 +0300
> Date: Sat, 4 May 2024 09:36:23 -0700
> Cc: 70519 <at> debbugs.gnu.org
> From: Paul Eggert <eggert <at> cs.ucla.edu>
> 
> On 2024-05-04 09:19, Eli Zaretskii wrote:
> > AFAIU, the --terminal option causes
> > Emacs to close its original stdin, so Ctrl-C does not send SIGINT to
> > Emacs.  But I'm nowhere near being an expert on that.  Paul, can you
> > please comment on that?
> 
> Closing stdin doesn't change a process's controlling terminal. On 
> GNU/Linux you need to use ioctl with TIOCSCTTY and there are a bunch of 
> other preconditions. See how emacs_spawn uses TIOCSCTTY:
> 
>         /* We ignore the return value
>            because faith <at> cs.unc.edu says that is necessary on Linux.  */
>         ioctl (std_in, TIOCSCTTY, 0);

So you are saying that the handling of --terminal in emacs.c is
incomplete, in that it doesn't call that ioctl on the new stdin?
because according to these comments in term.c, we do want the new
terminal to become our controlling terminal:

  /* 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.
     Otherwise NAME should be a path to the tty device file,
     e.g. "/dev/pts/7".
  [...]
  #ifndef DOS_NT
    if (!strcmp (name, dev_tty))
      ctty = 1;
  #endif
  [...]
      /* Open the terminal device.  */

      /* If !ctty, don't recognize it as our controlling terminal, and
	 don't make it the controlling tty if we don't have one now.

	 Alas, O_IGNORE_CTTY is a GNU extension that seems to be only
	 defined on Hurd.  On other systems, we need to explicitly
	 dissociate ourselves from the controlling tty when we want to
	 open a frame on the same terminal.  */
      int flags = O_RDWR | O_NOCTTY | (ctty ? 0 : O_IGNORE_CTTY);
      int fd = emacs_open (name, flags, 0);
      tty->input = tty->output
	= ((fd < 0 || ! isatty (fd))
	   ? NULL
	   : emacs_fdopen (fd, "w+"));
  [...]
      if (!O_IGNORE_CTTY && !ctty)
	dissociate_if_controlling_tty (fd);

In any case, is the result Helmut reports after typing Ctrl-C
expected, or does it mean we have a bug when using --terminal?

> This comment (and ignoring ioctl's return value) was added by rms in 
> commit 084fd64ac9daee2a89d393f07ce87ec8df543330 dated 1993. I'm 
> skeptical that the comment is true now. You might try adding code to 
> check the return value and report any errors, though Emacs shouldn't 
> abort (as it did before that 1993 change) if the ioctl fails.

But emacs_spawn is about starting a sub-process, which is something
different from what I'm talking about.  Here, the issue is the Emacs's
own terminal.

Thanks.




This bug report was last modified 1 year and 43 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.