From 2e008fb91f34b5a257305a1e9e42f60fb0aef81d Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Sun, 7 Dec 2003 22:37:12 +0000 Subject: Change use of BOOL, TRUE, FALSE to bool, true, false, as appropriate, throughout. * tty.cc (tty::common_init): Remove call to SetKernelObjectSecurity and edit some comments. * cygheap.h (init_cygheap::ctty): Add new element. * devices.in (device::parse): Remove special handling for /dev/tty. * devices.cc: Regenerate. * dtable.cc (build_fh_pc): Don't reset /dev/tty device. Let the device opener do that. * fhandler_termios.cc (tty_min::set_ctty): Redefine to _pinfo class. * fhandler_tty.cc (fhandler_tty_common::set_close_on_exec): Avoid setting noninherit flag for ctty. * tty.h: Move BOOLs to bools. (tty_min::set_ctty): Redeclare to _pinfo class. * pinfo.cc (_pinfo::set_ctty): Define new function based on tty_min::set_ctty. Change first argument from tty number to tty_min class. * pinfo.h (_pinfo::set_ctty): Declare. * fhandler_console.cc (fhandler_console::get_tty_stuff): Reflect move of set_ctty to _pinfo class. * fhandler_tty.cc (fhandler_tty_slave::open): Treat FH_TTY specially. Use saved cygheap value if it exists. Otherwise convert to real device and save on first time open. (fhandler_tty_common::dup): Potentially set controlling tty if duping a slave tty. * syscalls.cc (setsid): Close controlling tty in cygheap. * tty.cc: Change some BOOLs to bools. --- winsup/cygwin/fhandler_tty.cc | 55 ++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 16 deletions(-) (limited to 'winsup/cygwin/fhandler_tty.cc') diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 377a875fa..a27ee5827 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -447,10 +447,20 @@ fhandler_tty_slave::fhandler_tty_slave () int fhandler_tty_slave::open (int flags, mode_t) { + if (get_device () != FH_TTY) + /* nothing to do */; + else if (!cygheap->ctty.get_io_handle ()) + pc.dev.tty_to_real_device (); + else + { + *this = cygheap->ctty; + termios_printf ("copied tty fhandler from cygheap"); + return 1; + } + tcinit (cygwin_shared->tty[get_unit ()]); attach_tty (get_unit ()); - tc->set_ctty (get_unit (), flags); set_flags ((flags & ~O_TEXT) | O_BINARY); /* Create synchronisation events */ @@ -495,7 +505,7 @@ fhandler_tty_slave::open (int flags, mode_t) { acquire_output_mutex (500); inuse = get_ttyp ()->create_inuse (TTY_SLAVE_ALIVE); - get_ttyp ()->was_opened = TRUE; + get_ttyp ()->was_opened = true; release_output_mutex (); } @@ -508,7 +518,8 @@ fhandler_tty_slave::open (int flags, mode_t) return 0; } - HANDLE from_master_local, to_master_local; + HANDLE from_master_local = NULL; + HANDLE to_master_local = NULL; #ifdef USE_SERVER if (!wincap.has_security () @@ -557,6 +568,7 @@ fhandler_tty_slave::open (int flags, mode_t) set_io_handle (from_master_local); set_output_handle (to_master_local); + myself->set_ctty (get_ttyp (), flags, this); set_open_status (); if (fhandler_console::open_fhs++ == 0 && !GetConsoleCP () @@ -589,6 +601,8 @@ fhandler_tty_slave::close () if (!--fhandler_console::open_fhs && myself->ctty == -1) FreeConsole (); termios_printf ("decremented open_fhs %d", fhandler_console::open_fhs); + if (!exit_state && get_io_handle () == cygheap->ctty.get_io_handle ()) + return 1; return fhandler_tty_common::close (); } @@ -886,7 +900,6 @@ fhandler_tty_common::dup (fhandler_base *child) fts->tcinit (get_ttyp ()); attach_tty (get_unit ()); - tc->set_ctty (get_unit (), openflags); HANDLE nh; @@ -965,6 +978,10 @@ fhandler_tty_common::dup (fhandler_base *child) errind = 9; goto err; } + + if (get_major () == DEV_TTYS_MAJOR) + myself->set_ctty (get_ttyp (), openflags, (fhandler_tty_slave *) this); + return 0; err: @@ -1298,18 +1315,24 @@ fhandler_tty_common::set_close_on_exec (int val) set_inheritance (get_io_handle (), val); set_close_on_exec_flag (val); #endif - if (output_done_event) - set_inheritance (output_done_event, val); - if (ioctl_request_event) - set_inheritance (ioctl_request_event, val); - if (ioctl_done_event) - set_inheritance (ioctl_done_event, val); - if (inuse) - set_inheritance (inuse, val); - set_inheritance (output_mutex, val); - set_inheritance (input_mutex, val); - set_inheritance (input_available_event, val); - set_inheritance (output_handle, val); + if (get_major () == DEV_TTYS_MAJOR + && get_io_handle () == cygheap->ctty.get_io_handle ()) + set_close_on_exec_flag (val); + else + { + if (output_done_event) + set_inheritance (output_done_event, val); + if (ioctl_request_event) + set_inheritance (ioctl_request_event, val); + if (ioctl_done_event) + set_inheritance (ioctl_done_event, val); + if (inuse) + set_inheritance (inuse, val); + set_inheritance (output_mutex, val); + set_inheritance (input_mutex, val); + set_inheritance (input_available_event, val); + set_inheritance (output_handle, val); + } } void -- cgit v1.2.3