diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 92b0cf82c..550490a62 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,14 @@ +2015-03-05 Corinna Vinschen + + * 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 * fhandler.h (fhandler_base::get_echo_handle): New virtual method. diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 39fe6dffc..c7c90e28d 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -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); diff --git a/winsup/cygwin/release/1.7.36 b/winsup/cygwin/release/1.7.36 index 308a77225..1f89a9791 100644 --- a/winsup/cygwin/release/1.7.36 +++ b/winsup/cygwin/release/1.7.36 @@ -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 diff --git a/winsup/cygwin/tty.h b/winsup/cygwin/tty.h index f7a80e10f..c52f26307 100644 --- a/winsup/cygwin/tty.h +++ b/winsup/cygwin/tty.h @@ -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;