* 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.
This commit is contained in:
Christopher Faylor
2012-04-01 22:28:39 +00:00
parent c4ee9311c2
commit 881beea81d
4 changed files with 47 additions and 14 deletions

View File

@ -141,18 +141,15 @@ fhandler_console::set_unit ()
fh_devices this_unit = dev ();
fh_devices shared_unit =
(fh_devices) shared_console_info->tty_min_state.getntty ();
created = false;
devset = (shared_unit == this_unit || this_unit == FH_CONSOLE
|| this_unit == FH_CONIN || this_unit == FH_CONOUT
|| this_unit == FH_TTY) ?
shared_unit : FH_ERROR;
created = false;
}
else if ((myself->ctty != -1 && !iscons_dev (myself->ctty))
|| !(me = GetConsoleWindow ()))
{
created = false;
devset = FH_ERROR;
}
devset = FH_ERROR;
else
{
created = true;
@ -166,6 +163,12 @@ fhandler_console::set_unit ()
dev ().parse (devset);
if (devset != FH_ERROR)
pc.file_attributes (FILE_ATTRIBUTE_NORMAL);
else
{
set_io_handle (NULL);
set_output_handle (NULL);
created = false;
}
return created;
}