Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2012-04-02 02:28:39 +0400
committerChristopher Faylor <me@cgf.cx>2012-04-02 02:28:39 +0400
commit881beea81de7a0877c64c01ba74de5e8a8d9dfd5 (patch)
treec09074c640b7e836e09e2333d55675b4f4b6baf6 /winsup/cygwin/dtable.cc
parentc4ee9311c2c8cd01cadaa411900d284ba0fd2bdb (diff)
* dtable.cc (dtable::fixup_close): Define new function.
(dtable::fixup_after_exec): Use fixup_close() and detect when it was not possible to open an inherited file handle. (dtable::fixup_after_fork): Defensively close any file handles which were not, for some reason, inheritable. * dtable.h: Make #pragma once. (dtable::fixup_close): Declare new function. * fhandler_console.cc (fhandler_console::set_unit): Set I/O handles to NULL when this function fails.
Diffstat (limited to 'winsup/cygwin/dtable.cc')
-rw-r--r--winsup/cygwin/dtable.cc32
1 files changed, 23 insertions, 9 deletions
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index 1d59eccfb..2cc8229af 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -835,6 +835,17 @@ dtable::set_file_pointers_for_exec ()
}
void
+dtable::fixup_close (size_t i, fhandler_base *fh)
+{
+ if (fh->archetype)
+ {
+ debug_printf ("closing fd %d since it is an archetype", i);
+ fh->close_with_arch ();
+ }
+ release (i);
+}
+
+void
dtable::fixup_after_exec ()
{
first_fd_for_open = 0;
@@ -844,15 +855,11 @@ dtable::fixup_after_exec ()
{
fh->clear_readahead ();
fh->fixup_after_exec ();
- if (fh->close_on_exec ())
- {
- if (fh->archetype)
- {
- debug_printf ("closing fd %d since it is an archetype", i);
- fh->close_with_arch ();
- }
- release (i);
- }
+ /* Close the handle if it's close-on-exec or if an error was detected
+ (typically with opening a console in a gui app) by fixup_after_exec.
+ */
+ if (fh->close_on_exec () || !fh->get_io_handle ())
+ fixup_close (i, fh);
else if (fh->get_popen_pid ())
close (i);
else if (i == 0)
@@ -873,6 +880,13 @@ dtable::fixup_after_fork (HANDLE parent)
{
debug_printf ("fd %d (%s)", i, fh->get_name ());
fh->fixup_after_fork (parent);
+ if (!fh->get_io_handle ())
+ {
+ /* This should actually never happen but it's here to make sure
+ we don't crash due to access of an unopened file handle. */
+ fixup_close (i, fh);
+ continue;
+ }
}
if (i == 0)
SetStdHandle (std_consts[i], fh->get_io_handle ());