summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--winsup/cygwin/ChangeLog7
-rw-r--r--winsup/cygwin/fhandler_tty.cc37
2 files changed, 33 insertions, 11 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 702cfd5df..169db2a00 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -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>
* fhandler.h (class dev_console): Add backspace_keycode member.
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 7e8254c3c..30b6dda09 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -531,7 +531,8 @@ fhandler_tty_slave::open (int flags, mode_t)
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))
{
if (get_ttyp ()->master_pid < 0)
@@ -547,15 +548,24 @@ fhandler_tty_slave::open (int flags, mode_t)
set_errno (EAGAIN);
goto err_no_errno;
}
- termios_printf ("cannot dup handles via server. using old method.");
- HANDLE tty_owner = OpenProcess (PROCESS_DUP_HANDLE, FALSE,
- p->dwProcessId);
- if (tty_owner == NULL)
+ HANDLE tty_owner;
+ if (myself->pid == get_ttyp ()->master_pid)
{
- termios_printf ("can't open tty (%d) handle process %d",
- get_unit (), get_ttyp ()->master_pid);
- __seterrno ();
- goto err_no_msg;
+ /* 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.");
+ tty_owner = OpenProcess (PROCESS_DUP_HANDLE, FALSE, p->dwProcessId);
+ if (tty_owner == NULL)
+ {
+ termios_printf ("can't open tty (%d) handle process %d",
+ get_unit (), get_ttyp ()->master_pid);
+ __seterrno ();
+ goto err_no_msg;
+ }
}
if (!DuplicateHandle (tty_owner, get_ttyp ()->from_master,
@@ -577,7 +587,8 @@ fhandler_tty_slave::open (int flags, mode_t)
goto err;
}
VerifyHandle (to_master_local);
- CloseHandle (tty_owner);
+ if (tty_owner != GetCurrentProcess ())
+ CloseHandle (tty_owner);
}
termios_printf ("duplicated from_master %p->%p from tty_owner",
@@ -655,7 +666,11 @@ fhandler_tty_slave::cygserver_attach_tty (LPHANDLE from_master_ptr,
if (!from_master_ptr || !to_master_ptr)
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 ()->to_master);