Cygwin: pinfo: Additional fix for CTTY behavior.
The commit25c4ad6ea5
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. #include <unistd.h> #include <sys/fcntl.h> int main() { if (fork () == 0) { char *tty = ttyname(0); int fd; setsid(); fd = open(tty, O_RDWR); close(fd); fd = open(tty, O_RDWR); usleep (60000000L); } return 0; } Fixes:25c4ad6ea5
("Cygwin: pinfo: Align 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:
parent
a81fef51cf
commit
8e77725f31
|
@ -736,7 +736,6 @@ fhandler_termios::ioctl (int cmd, void *varg)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
myself->ctty = -1;
|
|
||||||
if (!myself->set_ctty (this, 0))
|
if (!myself->set_ctty (this, 0))
|
||||||
{
|
{
|
||||||
set_errno (EPERM);
|
set_errno (EPERM);
|
||||||
|
|
|
@ -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 flags & O_NOCTTY %y", __ctty (), ctty, tc.ntty, flags & O_NOCTTY);
|
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 (fh && (ctty <= 0 || ctty == tc.ntty) && !(flags & O_NOCTTY))
|
||||||
{
|
{
|
||||||
if (tc.getsid () && tc.getsid () != sid)
|
if (tc.getsid () && tc.getsid () != sid && ctty == -2)
|
||||||
; /* Do nothing if another session is associated with the TTY. */
|
; /* Do nothing if another session is associated with the TTY. */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -576,7 +576,8 @@ _pinfo::set_ctty (fhandler_termios *fh, int flags)
|
||||||
an obvious bug surfaces. */
|
an obvious bug surfaces. */
|
||||||
if (sid == pid && !tc.getsid ())
|
if (sid == pid && !tc.getsid ())
|
||||||
tc.setsid (sid);
|
tc.setsid (sid);
|
||||||
sid = tc.getsid ();
|
if (ctty > 0)
|
||||||
|
sid = tc.getsid ();
|
||||||
/* See above */
|
/* See above */
|
||||||
if ((!tc.getpgid () || being_debugged ()) && pgid == pid)
|
if ((!tc.getpgid () || being_debugged ()) && pgid == pid)
|
||||||
tc.setpgid (pgid);
|
tc.setpgid (pgid);
|
||||||
|
|
Loading…
Reference in New Issue