From 78ace8a7e5103099f20423acbc6d03c1b5d53fdd Mon Sep 17 00:00:00 2001 From: Egor Duda Date: Mon, 19 Mar 2001 18:27:37 +0000 Subject: [PATCH] * tty.h (tty::create_inuse): Add new parameter to allow non- inheritable 'inuse' events. * tty.cc (tty::create_inuse): Use new parameter. * fhandler_tty.cc (fhandler_tty_master::init): Ditto. * fhandler_tty.cc (fhandler_pty_master::open): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Create master_alive event. * tty.cc (tty_list::terminate): Close master_alive event. * fhandler_tty.cc (fhandler_tty_common::close): Send EOF to slaves when master side is closed. --- winsup/cygwin/ChangeLog | 13 +++++++++++++ winsup/cygwin/fhandler_tty.cc | 14 ++++++++++++-- winsup/cygwin/tty.cc | 5 +++-- winsup/cygwin/tty.h | 2 +- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index faecd47f0..3270764f7 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,16 @@ +2001-03-19 Egor Duda + + * tty.h (tty::create_inuse): Add new parameter to allow non- + inheritable 'inuse' events. + * tty.cc (tty::create_inuse): Use new parameter. + * fhandler_tty.cc (fhandler_tty_master::init): Ditto. + * fhandler_tty.cc (fhandler_pty_master::open): Ditto. + * fhandler_tty.cc (fhandler_tty_master::init): Create master_alive + event. + * tty.cc (tty_list::terminate): Close master_alive event. + * fhandler_tty.cc (fhandler_tty_common::close): Send EOF to slaves + when master side is closed. + Mon Mar 19 14:32:00 2001 Corinna Vinschen * mmap.cc (map::get_list_by_fd): Avoid calling `get_namehash' when diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index a2e815e66..7f140a5c3 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -61,6 +61,8 @@ fhandler_tty_master::init (int ntty) cygwin_shared->tty[ttynum]->common_init (this); + inuse = get_ttyp ()->create_inuse (TTY_MASTER_ALIVE, FALSE); + h = makethread (process_input, NULL, 0, "ttyin"); if (h == NULL) { @@ -482,7 +484,7 @@ fhandler_tty_slave::open (const char *, int flags, mode_t) /* FIXME: Needs a method to eliminate tty races */ { acquire_output_mutex (500); - inuse = get_ttyp ()->create_inuse (TTY_SLAVE_ALIVE); + inuse = get_ttyp ()->create_inuse (TTY_SLAVE_ALIVE, TRUE); get_ttyp ()->was_opened = TRUE; release_output_mutex (); } @@ -947,7 +949,7 @@ fhandler_pty_master::open (const char *, int flags, mode_t) return 0; cygwin_shared->tty[ttynum]->common_init (this); - inuse = get_ttyp ()->create_inuse (TTY_MASTER_ALIVE); + inuse = get_ttyp ()->create_inuse (TTY_MASTER_ALIVE, FALSE); set_flags (flags); termios_printf ("opened pty master tty%d<%p>", ttynum, this); @@ -969,6 +971,14 @@ fhandler_tty_common::close () termios_printf ("CloseHandle (output_mutex<%p>), %E", output_mutex); if (!ForceCloseHandle (input_mutex)) termios_printf ("CloseHandle (input_mutex<%p>), %E", input_mutex); + + /* Send EOF to slaves if master side is closed */ + if (!get_ttyp ()->master_alive ()) + { + termios_printf ("no more masters left. sending EOF" ); + SetEvent (input_available_event); + } + if (!ForceCloseHandle (input_available_event)) termios_printf ("CloseHandle (input_available_event<%p>), %E", input_available_event); if (!ForceCloseHandle1 (get_handle (), from_pty)) diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc index a986ec820..b71e32acb 100644 --- a/winsup/cygwin/tty.cc +++ b/winsup/cygwin/tty.cc @@ -138,6 +138,7 @@ tty_list::terminate (void) termios_printf ("tty %d master about to finish", ttynum); ForceCloseHandle1 (t->to_slave, to_pty); ForceCloseHandle1 (t->from_slave, from_pty); + CloseHandle (tty_master->inuse); WaitForSingleObject (tty_master->hThread, INFINITE); t->init (); @@ -299,13 +300,13 @@ tty::alive (const char *fmt) } HANDLE -tty::create_inuse (const char *fmt) +tty::create_inuse (const char *fmt, BOOL inherit) { HANDLE h; char buf[sizeof (TTY_MASTER_ALIVE) + 16]; __small_sprintf (buf, fmt, ntty); - h = CreateEvent (&sec_all, TRUE, FALSE, buf); + h = CreateEvent ((inherit ? &sec_all : &sec_all_nih), TRUE, FALSE, buf); termios_printf ("%s = %p", buf, h); if (!h) termios_printf ("couldn't open inuse event, %E", buf); diff --git a/winsup/cygwin/tty.h b/winsup/cygwin/tty.h index 43a82e0e4..6eb32b387 100644 --- a/winsup/cygwin/tty.h +++ b/winsup/cygwin/tty.h @@ -99,7 +99,7 @@ public: BOOL was_opened; /* True if opened at least once. */ void init (); - HANDLE create_inuse (const char *); + HANDLE create_inuse (const char *, BOOL); BOOL common_init (fhandler_pty_master *); BOOL alive (const char *fmt); BOOL slave_alive ();