diff options
author | Christopher Faylor <me@cgf.cx> | 2003-12-11 06:12:41 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2003-12-11 06:12:41 +0000 |
commit | 8e10c4311f9612951c82da5e844d51d985552d65 (patch) | |
tree | 23808644eb736e80e3160f30a07fe0357babe5f2 /winsup/cygwin/fhandler_tty.cc | |
parent | 3f23411449cf414d447bf793a20f42ed3f8e5061 (diff) | |
download | cygnal-8e10c4311f9612951c82da5e844d51d985552d65.tar.gz cygnal-8e10c4311f9612951c82da5e844d51d985552d65.tar.bz2 cygnal-8e10c4311f9612951c82da5e844d51d985552d65.zip |
* cygheap.h (cygheap_types): Add HEAP_ARCHETYPES.
(init_cheap::ctty): Change to pointer.
* dtable.h (dtable::find_archetype): Declare new function.
(dtable::add_archetype): Declare new function.
(dtable::delete_archetype): Declare new function.
(dtable::narchetypes): Declare.
(dtable::farchetypes): Declare.
(dtable::initial_archetype_size): Declare.
(dtable::dtable): Initialize new fields.
(dtable::initial_archetype_size): Declare.
* dtable.cc (dtable::find_archetype): Define new function.
(dtable::add_archetype): Define new function.
(dtable::delete_archetype): Define new function.
(dtable::initial_archetype_size): Define.
* fhandler.h (fhandler_base::archetype): Declare.
(fhandler_base::usecount): Declare.
* fhandler.cc (fhandler_base::fhandler_base): Initialize new fields.
* fhandler_console.cc (fhandler_console::get_tty_stuff): Pass NULL to third
argument of set_ctty.
* fhandler_tty.cc (fhandler_tty_slave::open): Accommodate new archetype method
to create only one instance of a tty.
(fhandler_tty_slave::close): Don't close handles unless archetype usecount is
zero. When that happens, close archetype too.
(fhandler_tty_slave::dup): Just copy archetype. Set use count appropriately.
Set ctty, if appropriate.
(fhandler_tty_common::dup): Remove slave considerations.
(fhandler_tty_common::set_close_on_exec): Remove cygheap->ctty considerations.
* pinfo.cc (_pinfo::set_ctty): Accommodate new archetype methods.
* pinfo.h (_pinfo::set_ctty): Make third argument explicit.
* syscalls.cc (close_all_files): Decrement controlling tty use count before
closing all handles to allow controlling tty to be closed. Remove previous
controlling tty considerations.
Diffstat (limited to 'winsup/cygwin/fhandler_tty.cc')
-rw-r--r-- | winsup/cygwin/fhandler_tty.cc | 75 |
1 files changed, 45 insertions, 30 deletions
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 4e888c030..85a4cc7fc 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -447,16 +447,16 @@ 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 ()) + if (get_device () == FH_TTY) pc.dev.tty_to_real_device (); - else + fhandler_tty_slave *arch = (fhandler_tty_slave *) + cygheap->fdtab.find_archetype (pc.dev); + if (arch) { - *this = cygheap->ctty; - fhandler_console::open_fhs++; + *this = *(fhandler_tty_slave *) arch; termios_printf ("copied tty fhandler from cygheap"); - return 1; + fhandler_console::open_fhs++; + goto out; } tcinit (cygwin_shared->tty[get_unit ()]); @@ -519,8 +519,9 @@ fhandler_tty_slave::open (int flags, mode_t) return 0; } - HANDLE from_master_local = NULL; - HANDLE to_master_local = NULL; + HANDLE from_master_local; + HANDLE to_master_local; + from_master_local = to_master_local = NULL; #ifdef USE_SERVER if (!wincap.has_security () @@ -569,7 +570,6 @@ 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 () @@ -590,8 +590,19 @@ fhandler_tty_slave::open (int flags, mode_t) if (b) init_console_handler (); } - termios_printf ("incremented open_fhs %d", fhandler_console::open_fhs); - termios_printf ("tty%d opened", get_unit ()); + + // FIXME: Do this better someday + arch = (fhandler_tty_slave *) cmalloc (HEAP_ARCHETYPES, sizeof (*this)); + *((fhandler_tty_slave **) cygheap->fdtab.add_archetype ()) = arch; + archetype = arch; + *arch = *this; + +out: + usecount = 0; + archetype->usecount++; + myself->set_ctty (get_ttyp (), flags, arch); + termios_printf ("%s opened, incremented open_fhs %d, archetype usecount %d", + pc.dev.name, fhandler_console::open_fhs, archetype->usecount); return 1; } @@ -601,10 +612,19 @@ fhandler_tty_slave::close () { if (!--fhandler_console::open_fhs && myself->ctty == -1) FreeConsole (); - termios_printf ("decremented open_fhs %d", fhandler_console::open_fhs); - if (myself->ctty >= 0 && get_io_handle () == cygheap->ctty.get_io_handle ()) - return 0; - return fhandler_tty_common::close (); + termios_printf ("decremented open_fhs %d, archetype usecount %d", + fhandler_console::open_fhs, archetype->usecount); + if (--archetype->usecount) + { + termios_printf ("just exiting because archetype usecount is > 0"); + return 0; + } + + termios_printf ("closing last open %s handle", pc.dev.name); + fhandler_tty_slave *arch = (fhandler_tty_slave *) archetype; + int res = fhandler_tty_common::close (); + cygheap->fdtab.delete_archetype (arch); + return res; } int @@ -888,8 +908,14 @@ int fhandler_tty_slave::dup (fhandler_base *child) { fhandler_console::open_fhs++; - termios_printf ("incremented open_fhs %d", fhandler_console::open_fhs); - return fhandler_tty_common::dup (child); + fhandler_tty_slave *arch = (fhandler_tty_slave *) archetype; + *(fhandler_tty_slave *) child = *arch; + archetype->usecount++; + child->usecount = 0; + myself->set_ctty (get_ttyp (), openflags, arch); + termios_printf ("incremented open_fhs %d, archetype usecount %d", + fhandler_console::open_fhs, archetype->usecount); + return 0; } int @@ -898,13 +924,6 @@ fhandler_tty_common::dup (fhandler_base *child) fhandler_tty_slave *fts = (fhandler_tty_slave *) child; int errind; - if (get_io_handle () == cygheap->ctty.get_io_handle ()) - { - *fts = cygheap->ctty; - termios_printf ("duped ctty"); - return 0; - } - fts->tcinit (get_ttyp ()); attach_tty (get_unit ()); @@ -987,9 +1006,6 @@ fhandler_tty_common::dup (fhandler_base *child) goto err; } - if (get_major () == DEV_TTYS_MAJOR) - myself->set_ctty (get_ttyp (), openflags, fts); - return 0; err: @@ -1315,8 +1331,7 @@ fhandler_pty_master::ptsname () void fhandler_tty_common::set_close_on_exec (int val) { - if (get_major () == DEV_TTYS_MAJOR - && get_io_handle () == cygheap->ctty.get_io_handle ()) + if (get_major () == DEV_TTYS_MAJOR) set_close_on_exec_flag (val); else { |