* tty.h (tty::set_master_ctl_closed): Rename from set_master_closed.

(tty::is_master_closed): Drop method.
	* fhandler_tty.cc (fhandler_pty_slave::open): Remove code prematurely
	bailing out if master control thread is not running.
	(fhandler_pty_slave::read): Don't generate SIGHUP if master control
	thread is not running.
	(fhandler_pty_master::close): Rearrange code to avoid stopping master
	control thread twice in multi-threaded scenarios.
This commit is contained in:
Corinna Vinschen 2015-03-05 13:58:03 +00:00
parent 3bf693dde1
commit 5e99eb1104
4 changed files with 28 additions and 24 deletions

View File

@ -1,3 +1,14 @@
2015-03-05 Corinna Vinschen <corinna@vinschen.de>
* tty.h (tty::set_master_ctl_closed): Rename from set_master_closed.
(tty::is_master_closed): Drop method.
* fhandler_tty.cc (fhandler_pty_slave::open): Remove code prematurely
bailing out if master control thread is not running.
(fhandler_pty_slave::read): Don't generate SIGHUP if master control
thread is not running.
(fhandler_pty_master::close): Rearrange code to avoid stopping master
control thread twice in multi-threaded scenarios.
2015-03-05 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (fhandler_base::get_echo_handle): New virtual method.

View File

@ -462,12 +462,6 @@ fhandler_pty_slave::open (int flags, mode_t)
goto err_no_errno;
}
if (get_ttyp ()->is_master_closed ())
{
errmsg = "*** master is closed";
set_errno (EAGAIN);
goto err_no_errno;
}
/* Three case for duplicating the pipe handles:
- Either we're the master. In this case, just duplicate the handles.
- Or, we have the right to open the master process for handle duplication.
@ -744,12 +738,6 @@ fhandler_pty_slave::read (void *ptr, size_t& len)
switch (cygwait (input_available_event, time_to_wait))
{
case WAIT_OBJECT_0:
if (get_ttyp ()->is_master_closed ())
{
raise (SIGHUP);
totalread = 0;
goto out;
}
break;
case WAIT_SIGNALED:
if (totalread > 0)
@ -1315,9 +1303,17 @@ fhandler_pty_master::close ()
__small_sprintf (buf, "\\\\.\\pipe\\cygwin-%S-pty%d-master-ctl",
&cygheap->installation_key, get_minor ());
CallNamedPipe (buf, &req, sizeof req, &repl, sizeof repl, &len, 500);
CloseHandle (master_ctl);
master_thread->detach ();
acquire_output_mutex (INFINITE);
if (master_ctl)
{
CallNamedPipe (buf, &req, sizeof req, &repl, sizeof repl, &len,
500);
CloseHandle (master_ctl);
master_thread->detach ();
get_ttyp ()->set_master_ctl_closed ();
master_ctl = NULL;
}
release_output_mutex ();
}
}
@ -1334,11 +1330,6 @@ fhandler_pty_master::close ()
if (have_execed || get_ttyp ()->master_pid != myself->pid)
termios_printf ("not clearing: %d, master_pid %d", have_execed, get_ttyp ()->master_pid);
else
{
get_ttyp ()->set_master_closed ();
SetEvent (input_available_event);
}
if (!ForceCloseHandle (input_available_event))
termios_printf ("CloseHandle (input_available_event<%p>), %E", input_available_event);

View File

@ -12,3 +12,6 @@ Bug Fixes
- Fix potential hang in pseudo ttys when generating ECHO output while the slave
is flooding the pty with output.
Addresses: https://cygwin.com/ml/cygwin/2015-03/msg00019.html
- Fix potential premature SIGHUP in pty code.
Addresses: https://cygwin.com/ml/cygwin/2015-03/msg00070.html

View File

@ -1,7 +1,7 @@
/* tty.h: shared tty info for cygwin
Copyright 2000, 2001, 2002, 2003, 2004, 2006, 2009, 2010, 2011, 2012, 2013
Red Hat, Inc.
Copyright 2000, 2001, 2002, 2003, 2004, 2006, 2009, 2010, 2011, 2012, 2013,
2015 Red Hat, Inc.
This file is part of Cygwin.
@ -129,8 +129,7 @@ public:
{ return open_mutex (INPUT_MUTEX, access); }
bool exists ();
bool not_allocated (HANDLE&, HANDLE&);
void set_master_closed () {master_pid = -1;}
bool is_master_closed () const {return master_pid == -1;}
void set_master_ctl_closed () {master_pid = -1;}
static void __stdcall create_master (int);
static void __stdcall init_session ();
friend class fhandler_pty_master;