From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 33ABC3858430; Tue, 10 Jan 2023 13:15:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 33ABC3858430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673356552; bh=tRlG/mRL6kmI/43TjtCl7f+c0paQFIkKoV5gOJAJLXU=; h=From:To:Subject:Date:From; b=JuWNsDjLxI48WUk4P7SZVG+xqK0r8fc6dLdVFhbZza+MRC2mA+XsXGdLceAv04/PB 2JW6udWYZW1crhwDIiIVMtNVQGOtKi6SX0kHnpa4VlTlIgWo0pcwwObsd0NBIf1Zmf e/7mMnWdlL57fbzlpGAmioPt6kPCGXjM0a27dj6w= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: pinfo: Additional fix for CTTY behavior. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: a81fef51cf9f1b9fad73ad85826f02f40d85fda6 X-Git-Newrev: 8e77725f3183e91762b2cac3682c7a3f0f4483f9 Message-Id: <20230110131552.33ABC3858430@sourceware.org> Date: Tue, 10 Jan 2023 13:15:52 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D8e77725f318= 3e91762b2cac3682c7a3f0f4483f9 commit 8e77725f3183e91762b2cac3682c7a3f0f4483f9 Author: Takashi Yano Date: Mon Dec 26 20:50:15 2022 +0900 Cygwin: pinfo: Additional fix for CTTY behavior. =20 The commit 25c4ad6ea52f did not fix the CTTY behavior enough. For example, in the following test case, TTY will be associated as a CTTY on the second open() call even though the TTY is already CTTY of another session. This patch fixes the issue. =20 #include #include =20 int main() { if (fork () =3D=3D 0) { char *tty =3D ttyname(0); int fd; setsid(); fd =3D open(tty, O_RDWR); close(fd); fd =3D open(tty, O_RDWR); usleep (60000000L); } return 0; } =20 Fixes: 25c4ad6ea52f ("Cygwin: pinfo: Align CTTY behavior to the statement of POSIX.") Reviewed-by: Corinna Vinschen Signed-off-by: Takashi Yano Diff: --- winsup/cygwin/fhandler/termios.cc | 1 - winsup/cygwin/pinfo.cc | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/fhandler/termios.cc b/winsup/cygwin/fhandler/ter= mios.cc index f94e20ff6..5b92cdd31 100644 --- a/winsup/cygwin/fhandler/termios.cc +++ b/winsup/cygwin/fhandler/termios.cc @@ -736,7 +736,6 @@ fhandler_termios::ioctl (int cmd, void *varg) return -1; } =20 - myself->ctty =3D -1; if (!myself->set_ctty (this, 0)) { set_errno (EPERM); diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index ff10d9cf8..ece346037 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -530,7 +530,7 @@ _pinfo::set_ctty (fhandler_termios *fh, int flags) debug_printf ("old %s, ctty device number %y, tc.ntty device number %y f= lags & O_NOCTTY %y", __ctty (), ctty, tc.ntty, flags & O_NOCTTY); if (fh && (ctty <=3D 0 || ctty =3D=3D tc.ntty) && !(flags & O_NOCTTY)) { - if (tc.getsid () && tc.getsid () !=3D sid) + if (tc.getsid () && tc.getsid () !=3D sid && ctty =3D=3D -2) ; /* Do nothing if another session is associated with the TTY. */ else { @@ -576,7 +576,8 @@ _pinfo::set_ctty (fhandler_termios *fh, int flags) an obvious bug surfaces. */ if (sid =3D=3D pid && !tc.getsid ()) tc.setsid (sid); - sid =3D tc.getsid (); + if (ctty > 0) + sid =3D tc.getsid (); /* See above */ if ((!tc.getpgid () || being_debugged ()) && pgid =3D=3D pid) tc.setpgid (pgid);