* fhandler.h (fhandler_console::fixup_after_fork_exec): Declare new function.

(fhandler_console::fixup_after_fork): Use fixup_after_fork_exec.
(fhandler_console::fixup_after_exec): Ditto.
* fhandler_console.cc (fhandler_console::fixup_after_fork): Delete definition.
(fhandler_console::fixup_after_fork_exec): Rename from fixup_after_exec.
* pinfo.cc (_pinfo::set_ctty): Don't play with console count here.
* syscalls.cc (close_all_files): Don't close cygheap ctty if hExeced since the
child will be copying information from us.
(setsid): Use myctty() rather than raw ctty #.
This commit is contained in:
Christopher Faylor 2005-11-14 05:36:16 +00:00
parent 59297e0464
commit 5a0826c3f8
6 changed files with 24 additions and 40 deletions

View File

@ -1,3 +1,15 @@
2005-11-14 Christopher Faylor <cgf@timesys.com>
* fhandler.h (fhandler_console::fixup_after_fork_exec): Declare new function.
(fhandler_console::fixup_after_fork): Use fixup_after_fork_exec.
(fhandler_console::fixup_after_exec): Ditto.
* fhandler_console.cc (fhandler_console::fixup_after_fork): Delete definition.
(fhandler_console::fixup_after_fork_exec): Rename from fixup_after_exec.
* pinfo.cc (_pinfo::set_ctty): Don't play with console count here.
* syscalls.cc (close_all_files): Don't close cygheap ctty if hExeced
since the child will be copying information from us.
(setsid): Use myctty() rather than raw ctty #.
2005-11-13 Christopher Faylor <cgf@timesys.com> 2005-11-13 Christopher Faylor <cgf@timesys.com>
* cygheap.h (init_cygheap::manage_console_count): Declare new function. * cygheap.h (init_cygheap::manage_console_count): Declare new function.

View File

@ -909,9 +909,10 @@ class fhandler_console: public fhandler_termios
select_record *select_read (select_record *s); select_record *select_read (select_record *s);
select_record *select_write (select_record *s); select_record *select_write (select_record *s);
select_record *select_except (select_record *s); select_record *select_except (select_record *s);
void fixup_after_exec (); void fixup_after_fork_exec ();
void fixup_after_exec () {fixup_after_fork_exec ();}
void fixup_after_fork (HANDLE) {fixup_after_fork_exec ();}
void set_close_on_exec (bool val); void set_close_on_exec (bool val);
void fixup_after_fork (HANDLE parent);
void set_input_state (); void set_input_state ();
void send_winch_maybe (); void send_winch_maybe ();
static tty_min *get_tty_stuff (int); static tty_min *get_tty_stuff (int);

View File

@ -695,10 +695,7 @@ fhandler_console::close ()
return 0; return 0;
} }
/* /* Special console dup to duplicate input and output handles. */
* Special console dup to duplicate input and output
* handles.
*/
int int
fhandler_console::dup (fhandler_base *child) fhandler_console::dup (fhandler_base *child)
@ -1757,29 +1754,6 @@ fhandler_console::set_close_on_exec (bool val)
set_no_inheritance (output_handle, val); set_no_inheritance (output_handle, val);
} }
void
fhandler_console::fixup_after_fork (HANDLE)
{
HANDLE h = get_handle ();
HANDLE oh = get_output_handle ();
/* Windows does not allow duplication of console handles between processes
so open the console explicitly. */
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);
CloseHandle (oh);
}
}
void __stdcall void __stdcall
set_console_title (char *title) set_console_title (char *title)
{ {
@ -1795,29 +1769,29 @@ set_console_title (char *title)
} }
void void
fhandler_console::fixup_after_exec () fhandler_console::fixup_after_fork_exec ()
{ {
HANDLE h = get_handle (); HANDLE h = get_handle ();
HANDLE oh = get_output_handle (); HANDLE oh = get_output_handle ();
if (close_on_exec () || 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); cygheap->manage_console_count ("fhandler_console::fixup_after_fork_exec", -1);
else else
{ {
bool sawerr = false; bool sawerr = false;
if (!get_io_handle ()) if (!get_io_handle ())
{ {
system_printf ("error opening input console handle after exec, errno %d, %E", get_errno ()); system_printf ("error opening input console handle after fork/exec, errno %d, %E", get_errno ());
sawerr = true; sawerr = true;
} }
if (!get_output_handle ()) if (!get_output_handle ())
{ {
system_printf ("error opening output console handle after exec, errno %d, %E", get_errno ()); system_printf ("error opening output console handle after fork/exec, errno %d, %E", get_errno ());
sawerr = true; sawerr = true;
} }
if (!sawerr) if (!sawerr)
system_printf ("error opening console after exec, errno %d, %E", get_errno ()); system_printf ("error opening console after fork/exec, errno %d, %E", get_errno ());
} }
if (!close_on_exec ()) if (!close_on_exec ())

View File

@ -450,8 +450,7 @@ fhandler_tty_slave::open (int flags, mode_t)
{ {
if (get_device () == FH_TTY) if (get_device () == FH_TTY)
pc.dev.tty_to_real_device (); pc.dev.tty_to_real_device ();
fhandler_tty_slave *arch = (fhandler_tty_slave *) fhandler_tty_slave *arch = (fhandler_tty_slave *) cygheap->fdtab.find_archetype (pc.dev);
cygheap->fdtab.find_archetype (pc.dev);
if (arch) if (arch)
{ {
*this = *(fhandler_tty_slave *) arch; *this = *(fhandler_tty_slave *) arch;

View File

@ -365,7 +365,6 @@ _pinfo::set_ctty (tty_min *tc, int flags, fhandler_tty_slave *arch)
if (arch) if (arch)
{ {
arch->usecount++; arch->usecount++;
cygheap->manage_console_count ("pinfo::set_ctty", 1);
report_tty_counts (cygheap->ctty, "ctty", ""); report_tty_counts (cygheap->ctty, "ctty", "");
} }
} }

View File

@ -114,7 +114,7 @@ close_all_files (bool norelease)
cygheap->fdtab.release (i); cygheap->fdtab.release (i);
} }
if (cygheap->ctty) if (!hExeced && cygheap->ctty)
cygheap->close_ctty (); cygheap->close_ctty ();
cygheap->fdtab.unlock (); cygheap->fdtab.unlock ();
@ -347,8 +347,7 @@ setsid (void)
myself->pgid = getpid (); myself->pgid = getpid ();
if (cygheap->ctty) if (cygheap->ctty)
cygheap->close_ctty (); cygheap->close_ctty ();
syscall_printf ("sid %d, pgid %d, ctty %d", myself->sid, myself->pgid, syscall_printf ("sid %d, pgid %d, %s", myself->sid, myself->pgid, myctty ());
myself->ctty);
return myself->sid; return myself->sid;
} }