Index: cygheap.h =================================================================== RCS file: /cvs/src/src/winsup/cygwin/cygheap.h,v retrieving revision 1.67 diff -r1.67 cygheap.h 243a244,252 > class cygheap_ctty > { > HANDLE from_master, to_master; > public: > void acquire (int); > void close (); > bool pass (fhandler_tty_slave &); > }; > 249a259 > cygheap_ctty inherited_ctty; Index: fhandler_termios.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/fhandler_termios.cc,v retrieving revision 1.48 diff -r1.48 fhandler_termios.cc 23a24,25 > #include "dtable.h" > #include "cygheap.h" 111a114,116 > > if (ttynum != TTY_CONSOLE) > cygheap->inherited_ctty.acquire(ttynum); Index: fhandler_tty.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/fhandler_tty.cc,v retrieving revision 1.110 diff -r1.110 fhandler_tty.cc 511a512,514 > /* Try inherited handles, if we are the ctty */ > if (!cygheap->inherited_ctty.pass (*this)) > { 521a525 > 560a565,566 > } > 1379a1386 > Index: syscalls.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/syscalls.cc,v retrieving revision 1.295 diff -r1.295 syscalls.cc 314a315 > cygheap->inherited_ctty.close (); Index: cygheap.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/cygheap.cc,v retrieving revision 1.86 diff -r1.86 cygheap.cc 25a26 > #include "pinfo.h" 446a448,527 > void > cygheap_ctty::acquire (int ttynum) > { > > if (from_master || to_master) > { > debug_printf ("Already got some handle"); > return; > } > > tty *tp = cygwin_shared->tty[ttynum]; > > HANDLE tty_owner; > > if (!(tty_owner = OpenProcess (PROCESS_DUP_HANDLE, FALSE, > tp->master_pid))) > debug_printf ("tty owner open %E"); > else > { > if (!DuplicateHandle (tty_owner, tp->from_master, > hMainProc, &from_master, 0, TRUE, > DUPLICATE_SAME_ACCESS)) > debug_printf ("can't duplicate input, %E"); > else if (!DuplicateHandle (tty_owner, tp->to_master, > hMainProc, &to_master, 0, TRUE, > DUPLICATE_SAME_ACCESS)) > { > CloseHandle (from_master); > from_master = NULL; > debug_printf ("can't duplicate output, %E"); > } > else > debug_printf("got them"); > CloseHandle (tty_owner); > } > } > > bool > cygheap_ctty::pass (fhandler_tty_slave & slave) > { > if (slave.tc->ntty != myself->ctty > || !(from_master) > || !(to_master)) > return false; > > HANDLE from_master_local = NULL, to_master_local = NULL; > > if (!DuplicateHandle (hMainProc, from_master, > hMainProc, &from_master_local, 0, TRUE, > DUPLICATE_SAME_ACCESS)) > debug_printf ("can't duplicate input, %E"); > else if (!DuplicateHandle (hMainProc, to_master, > hMainProc, &to_master_local, 0, TRUE, > DUPLICATE_SAME_ACCESS)) > { > debug_printf ("can't duplicate output, %E"); > CloseHandle (from_master_local); > } > else > { > debug_printf("OK"); > slave.set_io_handle (from_master_local); > slave.set_output_handle (to_master_local); > return true; > } > return false; > } > > void > cygheap_ctty::close() > { > if (to_master) > CloseHandle (to_master); > if (from_master) > CloseHandle (from_master); > > to_master = from_master = NULL; > > debug_printf ("OK"); > }