* cygheap.h (init_cygheap::manage_console_count): Declare new function.

(init_cygheap::console_count): Renamed from open_fhs.  Make private.
* cygheap.cc (init_cygheap::manage_console_count): Define new function.
* dtable.cc (dtable::fixup_after_exec): Always call fixup_after_exec on
elements of fd even when they are about to be closed.
* fhandler.h (report_tty_counts): Remove open_fhs from debugging output.
* fhandler_console.cc (fhandler_console::open): Use manage_console_count rather
than manipulating count directly.
(fhandler_console::close): Ditto.
(fhandler_console::fixup_after_fork): Ditto.
(fhandler_console::fixup_after_exec): Ditto.  Don't close handles if
close_on_exec.
* fhandler_tty.cc (fhandler_tty_slave::open): Use manage_console_count() rather
than manipulating count directly.  Reflect change in arguments to
report_tty_counts().
(fhandler_tty_slave::close): Ditto for both.
(fhandler_tty_slave::dup): Ditto for both.
(fhandler_tty_slave::ioctl): Use myctty() rather than raw ctty #.
(fhandler_tty_slave::fixup_after_fork): Reflect change in arguments to
report_tty_counts().
(fhandler_tty_master::init_console): Use manage_console_count() rather than
manipulating count directly.
* fhandler_clipboard.cc (fhandler_dev_clipboard::fixup_after_exec): Don't
perform any operations if close_on_exec.
* fhandler_dsp.cc (fhandler_dev_dsp::fixup_after_exec): Ditto.
* fhandler_raw.cc (fhandler_dev_raw::fixup_after_exec): Ditto.
* fhandler_serial.cc (fhandler_serial::fixup_after_exec): Ditto.
* pinfo.h (_pinfo::_ctty): Declare new function.
(myctty): Declare new macro.
(__ctty): Declare new macro.
* pinfo.cc (_pinfo::_ctty): Define new function.
(_pinfo::set_ctty): Use manage_console_count() rather than manipulating count
directly.
* signal.cc (kill_pgrp): Use myctty() and __ctty() macros rather than raw ctty
#.
* syscalls.cc (setsid): Ditto.  Use manage_console_count() rather than
manipulating count directly.
This commit is contained in:
Christopher Faylor
2005-11-14 04:28:45 +00:00
parent 70c500b343
commit 59297e0464
18 changed files with 148 additions and 71 deletions

View File

@@ -678,8 +678,7 @@ fhandler_console::open (int flags, mode_t)
tc->rstcons (false);
set_open_status ();
cygheap->open_fhs++;
debug_printf ("incremented open_fhs, now %d", cygheap->open_fhs);
cygheap->manage_console_count ("fhandler_console::open", 1);
debug_printf ("opened conin$ %p, conout$ %p", get_io_handle (),
get_output_handle ());
@@ -691,12 +690,8 @@ fhandler_console::close ()
{
CloseHandle (get_io_handle ());
CloseHandle (get_output_handle ());
if (!hExeced && --(cygheap->open_fhs) <= 0 && myself->ctty != TTY_CONSOLE)
{
syscall_printf ("open_fhs %d", cygheap->open_fhs);
FreeConsole ();
}
debug_printf ("decremented open_fhs, now %d", cygheap->open_fhs);
if (!hExeced)
cygheap->manage_console_count ("fhandler_console::close", -1);
return 0;
}
@@ -1771,10 +1766,13 @@ fhandler_console::fixup_after_fork (HANDLE)
/* Windows does not allow duplication of console handles between processes
so open the console explicitly. */
cygheap->open_fhs--; /* The downside of storing this in cygheap. */
if (!open (O_NOCTTY | get_flags (), 0))
system_printf ("error opening console after fork, %E");
/* Need to decrement console_count since this open is basically a no-op to reopen
the console and we've already recorded that fact. */
cygheap->manage_console_count ("fhandler_console::fixup_after_fork", -1);
if (!close_on_exec ())
{
CloseHandle (h);
@@ -1802,8 +1800,9 @@ fhandler_console::fixup_after_exec ()
HANDLE h = get_handle ();
HANDLE oh = get_output_handle ();
cygheap->open_fhs--; /* The downside of storing this in cygheap. */
if (!open (O_NOCTTY | get_flags (), 0))
if (close_on_exec () || open (O_NOCTTY | get_flags (), 0))
cygheap->manage_console_count ("fhandler_console::fixup_after_exec", -1);
else
{
bool sawerr = false;
if (!get_io_handle ())
@@ -1821,6 +1820,9 @@ fhandler_console::fixup_after_exec ()
system_printf ("error opening console after exec, errno %d, %E", get_errno ());
}
CloseHandle (h);
CloseHandle (oh);
if (!close_on_exec ())
{
CloseHandle (h);
CloseHandle (oh);
}
}