Cygwin: pinfo: Align CTTY behavior to the statement of POSIX.

POSIX states "A terminal may be the controlling terminal for at most
one session."
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap11.html

However, in cygwin, multiple sessions could be associated with the
same TTY. This patch aligns CTTY behavior to the statement of POSIX.

Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
This commit is contained in:
Takashi Yano 2022-12-20 20:26:36 +09:00
parent 5841b2f6a4
commit 25c4ad6ea5
3 changed files with 29 additions and 17 deletions

View File

@ -737,7 +737,11 @@ fhandler_termios::ioctl (int cmd, void *varg)
}
myself->ctty = -1;
myself->set_ctty (this, 0);
if (!myself->set_ctty (this, 0))
{
set_errno (EPERM);
return -1;
}
return 0;
}

View File

@ -127,6 +127,8 @@ void
init_cygheap::close_ctty ()
{
debug_printf ("closing cygheap->ctty %p", cygheap->ctty);
if (cygheap->ctty->tc ()->getsid () == pid)
cygheap->ctty->tc ()->setsid (0); /* Release CTTY ownership */
cygheap->ctty->close_with_arch ();
cygheap->ctty = NULL;
}

View File

@ -529,11 +529,16 @@ _pinfo::set_ctty (fhandler_termios *fh, int flags)
tty_min& tc = *fh->tc ();
debug_printf ("old %s, ctty device number %y, tc.ntty device number %y flags & O_NOCTTY %y", __ctty (), ctty, tc.ntty, flags & O_NOCTTY);
if (fh && (ctty <= 0 || ctty == tc.ntty) && !(flags & O_NOCTTY))
{
if (tc.getsid () && tc.getsid () != sid)
; /* Do nothing if another session is associated with the TTY. */
else
{
ctty = tc.ntty;
if (cygheap->ctty != fh->archetype)
{
debug_printf ("cygheap->ctty %p, archetype %p", cygheap->ctty, fh->archetype);
debug_printf ("cygheap->ctty %p, archetype %p",
cygheap->ctty, fh->archetype);
if (!cygheap->ctty)
syscall_printf ("ctty was NULL");
else
@ -550,6 +555,7 @@ _pinfo::set_ctty (fhandler_termios *fh, int flags)
report_tty_counts (cygheap->ctty, "ctty", "");
}
}
}
lock_ttys here;
syscall_printf ("attaching %s sid %d, pid %d, pgid %d, tty->pgid %d, tty->sid %d",