diff --git a/winsup/cygwin/fhandler/termios.cc b/winsup/cygwin/fhandler/termios.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; } - myself->ctty = -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 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) + if (tc.getsid () && tc.getsid () != sid && ctty == -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 == pid && !tc.getsid ()) tc.setsid (sid); - sid = tc.getsid (); + if (ctty > 0) + sid = tc.getsid (); /* See above */ if ((!tc.getpgid () || being_debugged ()) && pgid == pid) tc.setpgid (pgid);