* fhandler_tty.cc (fhandler_tty_slave::open): Add code to duplicate

handles within a single process to simplify openpty case.
	(fhandler_tty_slave::cygserver_attach_tty): Correctly send Windows PID
	to cygserver, rather than the Cygwin PID.
This commit is contained in:
Corinna Vinschen 2010-04-12 13:28:06 +00:00
parent 7092cadf76
commit 42e9cefd71
2 changed files with 33 additions and 11 deletions

View File

@ -1,3 +1,10 @@
2010-04-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_tty.cc (fhandler_tty_slave::open): Add code to duplicate
handles within a single process to simplify openpty case.
(fhandler_tty_slave::cygserver_attach_tty): Correctly send Windows PID
to cygserver, rather than the Cygwin PID.
2010-04-11 Corinna Vinschen <corinna@vinschen.de> 2010-04-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class dev_console): Add backspace_keycode member. * fhandler.h (class dev_console): Add backspace_keycode member.

View File

@ -531,7 +531,8 @@ fhandler_tty_slave::open (int flags, mode_t)
goto err_no_errno; goto err_no_errno;
} }
if (cygserver_running == CYGSERVER_UNAVAIL if (myself->pid == get_ttyp ()->master_pid
|| cygserver_running == CYGSERVER_UNAVAIL
|| !cygserver_attach_tty (&from_master_local, &to_master_local)) || !cygserver_attach_tty (&from_master_local, &to_master_local))
{ {
if (get_ttyp ()->master_pid < 0) if (get_ttyp ()->master_pid < 0)
@ -547,9 +548,17 @@ fhandler_tty_slave::open (int flags, mode_t)
set_errno (EAGAIN); set_errno (EAGAIN);
goto err_no_errno; goto err_no_errno;
} }
HANDLE tty_owner;
if (myself->pid == get_ttyp ()->master_pid)
{
/* This is the most common case, just calling openpty. */
termios_printf ("dup handles within myself.");
tty_owner = GetCurrentProcess ();
}
else
{
termios_printf ("cannot dup handles via server. using old method."); termios_printf ("cannot dup handles via server. using old method.");
HANDLE tty_owner = OpenProcess (PROCESS_DUP_HANDLE, FALSE, tty_owner = OpenProcess (PROCESS_DUP_HANDLE, FALSE, p->dwProcessId);
p->dwProcessId);
if (tty_owner == NULL) if (tty_owner == NULL)
{ {
termios_printf ("can't open tty (%d) handle process %d", termios_printf ("can't open tty (%d) handle process %d",
@ -557,6 +566,7 @@ fhandler_tty_slave::open (int flags, mode_t)
__seterrno (); __seterrno ();
goto err_no_msg; goto err_no_msg;
} }
}
if (!DuplicateHandle (tty_owner, get_ttyp ()->from_master, if (!DuplicateHandle (tty_owner, get_ttyp ()->from_master,
GetCurrentProcess (), &from_master_local, 0, TRUE, GetCurrentProcess (), &from_master_local, 0, TRUE,
@ -577,6 +587,7 @@ fhandler_tty_slave::open (int flags, mode_t)
goto err; goto err;
} }
VerifyHandle (to_master_local); VerifyHandle (to_master_local);
if (tty_owner != GetCurrentProcess ())
CloseHandle (tty_owner); CloseHandle (tty_owner);
} }
@ -655,7 +666,11 @@ fhandler_tty_slave::cygserver_attach_tty (LPHANDLE from_master_ptr,
if (!from_master_ptr || !to_master_ptr) if (!from_master_ptr || !to_master_ptr)
return 0; return 0;
client_request_attach_tty req ((DWORD) get_ttyp ()->master_pid, pinfo p (get_ttyp ()->master_pid);
if (!p)
return 0;
client_request_attach_tty req (p->dwProcessId,
(HANDLE) get_ttyp ()->from_master, (HANDLE) get_ttyp ()->from_master,
(HANDLE) get_ttyp ()->to_master); (HANDLE) get_ttyp ()->to_master);