diff options
author | Christopher Faylor <me@cgf.cx> | 2009-07-03 18:05:51 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2009-07-03 18:05:51 +0000 |
commit | 3c4f2024a1c4cddd0fc4239827de4f83528c17f7 (patch) | |
tree | ba9c461ab14dd6238396e817d0fe6722cb8f2a74 /winsup/cygwin/tty.cc | |
parent | 3e62013829163ec02af6671bc38ea4715a8cb8fb (diff) | |
download | newlib-3c4f2024a1c4cddd0fc4239827de4f83528c17f7.zip newlib-3c4f2024a1c4cddd0fc4239827de4f83528c17f7.tar.gz newlib-3c4f2024a1c4cddd0fc4239827de4f83528c17f7.tar.bz2 |
* dcrt0.cc (jit_debug): New global.
(initial_env): Set jit_debug when we are automatically starting a gdb process.
* dtable.cc (dtable::get_debugger_info): Don't tty tricks when we are being
debugged by our own captive gdb, as determined by jit_debug == true.
(dtable::init_std_file_from_handle): Detect errors when initializing a tty
early rather than at random points later.
* fhandler.h (fhandler_*::init): Return int to indicate success/failure.
* fhandler.cc (fhandler_base::init): Reflect change in return value.
* pipe.cc (fhandler_pipe::init): Ditto.
(fhandler_pipe::create_selectable): Don't say we're retrying when we aren't.
* fhandler_console.cc (fhandler_console::init): Ditto. Return success/failure.
* fhandler_serial.cc (fhandler_serial::init): Ditto.
* fhandler_tty.cc (fhandler_tty_slave::init): Ditto.
(fhandler_tty_slave::open): Make debugging output more detailed.
* tty.cc (tty_list::terminate): Don't close I/O handles before all slaves have
checked in.
(tty::slave_alive): Make a non-inlined function. Check if tty pipe handles can
be created as an additional exists check.
* tty.h (tty::slave_alive): Just define here.
Diffstat (limited to 'winsup/cygwin/tty.cc')
-rw-r--r-- | winsup/cygwin/tty.cc | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc index f831a53..624805f 100644 --- a/winsup/cygwin/tty.cc +++ b/winsup/cygwin/tty.cc @@ -147,8 +147,6 @@ tty_list::terminate () if (ttynum != -1 && tty_master && ttys[ttynum].master_pid == myself->pid) { tty *t = ttys + ttynum; - CloseHandle (tty_master->from_master); - CloseHandle (tty_master->to_master); /* Wait for children which rely on tty handling in this process to go away */ for (int i = 0; ; i++) @@ -166,6 +164,8 @@ tty_list::terminate () } lock_ttys here (); + CloseHandle (tty_master->from_master); + CloseHandle (tty_master->to_master); termios_printf ("tty %d master about to finish", ttynum); CloseHandle (tty_master->get_io_handle ()); @@ -209,7 +209,7 @@ tty_list::init () /* Search for tty class for our console. Allocate new tty if our process is the only cygwin process in the current console. Return tty number or -1 if error. - If flag == 0, just find a free tty. + If with_console == 0, just find a free tty. */ int tty_list::allocate (bool with_console) @@ -218,8 +218,6 @@ tty_list::allocate (bool with_console) int freetty = -1; HANDLE hmaster = NULL; - /* FIXME: This whole function needs a protective mutex. */ - lock_ttys here; if (!with_console) @@ -261,7 +259,7 @@ tty_list::allocate (bool with_console) } } - /* There is no tty allocated to console, allocate the first free found */ + /* There is no tty allocated to console; allocate the first free found */ if (freetty == -1) goto out; @@ -295,6 +293,30 @@ tty::slave_alive () } bool +tty::exists () +{ + /* Attempt to open the from-master side of the tty. If it is accessible + then it exists although it may have been privileges to actually use it. */ + char pipename[sizeof("ttyNNNN-from-master")]; + __small_sprintf (pipename, "tty%d-from-master", ntty); + HANDLE r, w; + int res = fhandler_pipe::create_selectable (&sec_none_nih, r, w, 0, pipename); + if (res) + return true; + + CloseHandle (r); + CloseHandle (w); + + HANDLE h = open_output_mutex (); + if (h) + { + CloseHandle (h); + return true; + } + return slave_alive (); +} + +bool tty::alive (const char *fmt) { HANDLE ev; |