Move open_fhs from fhandler.h to cygheap.h for easier tracking. Accommodate
this change throughout. * dtable.cc (dtable::add_archetype): Use correct count when iterating through *active* archetypes. * dtable.cc (dtable::fixup_after_exec): Close handle if close_on_exec and archetype exists since archetype currently does not set windows close-on-exec flag (FIXME). * fhandler_tty.cc (fhandler_tty_slave::open): Change debugging output slightly. (fhandler_tty_slave::close): Ditto. (fhandler_tty_slave::fixup_after_fork): Just report on inherited use counts since since archetype currently does not set windows close-on-exec flag (FIXME). * pinfo.cc (_pinfo::set_ctty): Change debugging output slightly. * cygheap.cc (cygheap_init): Remove open_fhs accommodation and use count reporting. * perthread.h (vfork_save::fhctty): New element. * perthread.h (vfork_save::open_fhs): New element. * fork.cc (vfork): Muck around with ctty and open_fhs stuff, both of which are now saved in the vfork_save structure.
This commit is contained in:
parent
e97377932b
commit
8ed5c9b629
|
@ -1,3 +1,26 @@
|
||||||
|
2003-12-29 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
|
Move open_fhs from fhandler.h to cygheap.h for easier tracking.
|
||||||
|
Accommodate this change throughout.
|
||||||
|
* dtable.cc (dtable::add_archetype): Use correct count when iterating
|
||||||
|
through *active* archetypes.
|
||||||
|
* dtable.cc (dtable::fixup_after_exec): Close handle if close_on_exec
|
||||||
|
and archetype exists since archetype currently does not set windows
|
||||||
|
close-on-exec flag (FIXME).
|
||||||
|
* fhandler_tty.cc (fhandler_tty_slave::open): Change debugging output
|
||||||
|
slightly.
|
||||||
|
(fhandler_tty_slave::close): Ditto.
|
||||||
|
(fhandler_tty_slave::fixup_after_fork): Just report on inherited use
|
||||||
|
counts since since archetype currently does not set windows
|
||||||
|
close-on-exec flag (FIXME).
|
||||||
|
* pinfo.cc (_pinfo::set_ctty): Change debugging output slightly.
|
||||||
|
* cygheap.cc (cygheap_init): Remove open_fhs accommodation and use
|
||||||
|
count reporting.
|
||||||
|
* perthread.h (vfork_save::fhctty): New element.
|
||||||
|
* perthread.h (vfork_save::open_fhs): New element.
|
||||||
|
* fork.cc (vfork): Muck around with ctty and open_fhs stuff, both of
|
||||||
|
which are now saved in the vfork_save structure.
|
||||||
|
|
||||||
2003-12-27 Christopher Faylor <cgf@redhat.com>
|
2003-12-27 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
* fhandler.h (fhandler_tty_slave::archetype): Make public.
|
* fhandler.h (fhandler_tty_slave::archetype): Make public.
|
||||||
|
|
|
@ -212,11 +212,6 @@ cygheap_init ()
|
||||||
&& (set_process_privilege (SE_CREATE_GLOBAL_NAME, true) >= 0
|
&& (set_process_privilege (SE_CREATE_GLOBAL_NAME, true) >= 0
|
||||||
|| GetLastError () == ERROR_NO_SUCH_PRIVILEGE)
|
|| GetLastError () == ERROR_NO_SUCH_PRIVILEGE)
|
||||||
? "Global\\" : "");
|
? "Global\\" : "");
|
||||||
if (cygheap->ctty)
|
|
||||||
{
|
|
||||||
fhandler_console::open_fhs++;
|
|
||||||
report_tty_counts (cygheap->ctty, "inherited", "incremented ", "unchanged ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copyright (C) 1997, 2000 DJ Delorie */
|
/* Copyright (C) 1997, 2000 DJ Delorie */
|
||||||
|
|
|
@ -262,6 +262,7 @@ struct init_cygheap
|
||||||
struct sigaction *sigs;
|
struct sigaction *sigs;
|
||||||
|
|
||||||
fhandler_tty_slave *ctty; /* Current tty */
|
fhandler_tty_slave *ctty; /* Current tty */
|
||||||
|
int open_fhs;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CYGHEAPSIZE (sizeof (init_cygheap) + (20000 * sizeof (fhandler_union)) + (5 * 65536))
|
#define CYGHEAPSIZE (sizeof (init_cygheap) + (20000 * sizeof (fhandler_union)) + (5 * 65536))
|
||||||
|
|
|
@ -186,10 +186,10 @@ dtable::add_archetype ()
|
||||||
void
|
void
|
||||||
dtable::delete_archetype (fhandler_base *fh)
|
dtable::delete_archetype (fhandler_base *fh)
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < narchetypes; i++)
|
for (unsigned i = 0; i < farchetype; i++)
|
||||||
if (fh == archetypes[i])
|
if (fh == archetypes[i])
|
||||||
{
|
{
|
||||||
debug_printf ("deleting archive element %d for %s", i, fh->get_name ());
|
debug_printf ("deleting element %d for %s", i, fh->get_name ());
|
||||||
if (i < --farchetype)
|
if (i < --farchetype)
|
||||||
archetypes[i] = archetypes[farchetype];
|
archetypes[i] = archetypes[farchetype];
|
||||||
break;
|
break;
|
||||||
|
@ -660,7 +660,11 @@ dtable::fixup_after_exec (HANDLE parent)
|
||||||
{
|
{
|
||||||
fh->clear_readahead ();
|
fh->clear_readahead ();
|
||||||
if (fh->get_close_on_exec ())
|
if (fh->get_close_on_exec ())
|
||||||
|
{
|
||||||
|
if (fh->archetype)
|
||||||
|
fh->close ();
|
||||||
release (i);
|
release (i);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fh->fixup_after_exec (parent);
|
fh->fixup_after_exec (parent);
|
||||||
|
@ -704,7 +708,7 @@ dtable::vfork_child_dup ()
|
||||||
if (cygheap->ctty)
|
if (cygheap->ctty)
|
||||||
{
|
{
|
||||||
cygheap->ctty->usecount++;
|
cygheap->ctty->usecount++;
|
||||||
fhandler_console::open_fhs++;
|
cygheap->open_fhs++;
|
||||||
report_tty_counts (cygheap->ctty, "vfork dup", "incremented ", "");
|
report_tty_counts (cygheap->ctty, "vfork dup", "incremented ", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -742,9 +746,6 @@ dtable::vfork_parent_restore ()
|
||||||
fds_on_hold = NULL;
|
fds_on_hold = NULL;
|
||||||
cfree (deleteme);
|
cfree (deleteme);
|
||||||
|
|
||||||
if (cygheap->ctty)
|
|
||||||
cygheap->ctty->close ();
|
|
||||||
|
|
||||||
ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "restore");
|
ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "restore");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -758,7 +759,6 @@ dtable::vfork_child_fixup ()
|
||||||
fhandler_base **saveme = fds;
|
fhandler_base **saveme = fds;
|
||||||
fds = fds_on_hold;
|
fds = fds_on_hold;
|
||||||
|
|
||||||
int old_open_fhs = fhandler_console::open_fhs;
|
|
||||||
fhandler_base *fh;
|
fhandler_base *fh;
|
||||||
for (int i = 0; i < (int) size; i++)
|
for (int i = 0; i < (int) size; i++)
|
||||||
if ((fh = fds[i]) != NULL)
|
if ((fh = fds[i]) != NULL)
|
||||||
|
@ -773,10 +773,6 @@ dtable::vfork_child_fixup ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fhandler_console::open_fhs = old_open_fhs;
|
|
||||||
if (cygheap->ctty)
|
|
||||||
cygheap->ctty->close ();
|
|
||||||
|
|
||||||
fds = saveme;
|
fds = saveme;
|
||||||
cfree (fds_on_hold);
|
cfree (fds_on_hold);
|
||||||
fds_on_hold = NULL;
|
fds_on_hold = NULL;
|
||||||
|
|
|
@ -829,8 +829,6 @@ class fhandler_console: public fhandler_termios
|
||||||
void set_cursor_maybe ();
|
void set_cursor_maybe ();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static int open_fhs;
|
|
||||||
|
|
||||||
fhandler_console ();
|
fhandler_console ();
|
||||||
|
|
||||||
fhandler_console* is_console () { return this; }
|
fhandler_console* is_console () { return this; }
|
||||||
|
@ -1197,7 +1195,7 @@ struct fhandler_nodevice: public fhandler_base
|
||||||
#define report_tty_counts(fh, call, fhs_op, use_op) \
|
#define report_tty_counts(fh, call, fhs_op, use_op) \
|
||||||
termios_printf ("%s %s, %sopen_fhs %d, %susecount %d",\
|
termios_printf ("%s %s, %sopen_fhs %d, %susecount %d",\
|
||||||
fh->ttyname (), call,\
|
fh->ttyname (), call,\
|
||||||
fhs_op, fhandler_console::open_fhs,\
|
fhs_op, cygheap->open_fhs,\
|
||||||
use_op, ((fhandler_tty_slave *) fh)->archetype->usecount);
|
use_op, ((fhandler_tty_slave *) fh)->archetype->usecount);
|
||||||
|
|
||||||
typedef union
|
typedef union
|
||||||
|
|
|
@ -73,8 +73,6 @@ static console_state NO_COPY *shared_console_info;
|
||||||
|
|
||||||
dev_console NO_COPY *fhandler_console::dev_state;
|
dev_console NO_COPY *fhandler_console::dev_state;
|
||||||
|
|
||||||
int NO_COPY fhandler_console::open_fhs;
|
|
||||||
|
|
||||||
/* Allocate and initialize the shared record for the current console.
|
/* Allocate and initialize the shared record for the current console.
|
||||||
Returns a pointer to shared_console_info. */
|
Returns a pointer to shared_console_info. */
|
||||||
tty_min *
|
tty_min *
|
||||||
|
@ -664,10 +662,10 @@ fhandler_console::open (int flags, mode_t)
|
||||||
|
|
||||||
TTYCLEARF (RSTCONS);
|
TTYCLEARF (RSTCONS);
|
||||||
set_open_status ();
|
set_open_status ();
|
||||||
open_fhs++;
|
cygheap->open_fhs++;
|
||||||
debug_printf ("incremented open_fhs, now %d", open_fhs);
|
debug_printf ("incremented open_fhs, now %d", cygheap->open_fhs);
|
||||||
debug_printf ("opened conin$ %p, conout$ %p",
|
debug_printf ("opened conin$ %p, conout$ %p", get_io_handle (),
|
||||||
get_io_handle (), get_output_handle ());
|
get_output_handle ());
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -679,14 +677,14 @@ fhandler_console::close (void)
|
||||||
CloseHandle (get_output_handle ());
|
CloseHandle (get_output_handle ());
|
||||||
set_io_handle (NULL);
|
set_io_handle (NULL);
|
||||||
set_output_handle (NULL);
|
set_output_handle (NULL);
|
||||||
if (!cygheap->fdtab.in_vfork_cleanup () && --open_fhs <= 0
|
if (!cygheap->fdtab.in_vfork_cleanup () && --(cygheap->open_fhs) <= 0
|
||||||
&& myself->ctty != TTY_CONSOLE)
|
&& myself->ctty != TTY_CONSOLE)
|
||||||
{
|
{
|
||||||
syscall_printf ("open_fhs %d, freeing console %p",
|
syscall_printf ("open_fhs %d, freeing console %p", cygheap->open_fhs,
|
||||||
fhandler_console::open_fhs, myself->ctty);
|
myself->ctty);
|
||||||
FreeConsole ();
|
FreeConsole ();
|
||||||
}
|
}
|
||||||
debug_printf ("decremented open_fhs, now %d", open_fhs);
|
debug_printf ("decremented open_fhs, now %d", cygheap->open_fhs);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -455,8 +455,8 @@ fhandler_tty_slave::open (int flags, mode_t)
|
||||||
if (arch)
|
if (arch)
|
||||||
{
|
{
|
||||||
*this = *(fhandler_tty_slave *) arch;
|
*this = *(fhandler_tty_slave *) arch;
|
||||||
termios_printf ("copied tty fhandler from cygheap");
|
termios_printf ("copied tty fhandler archetype");
|
||||||
fhandler_console::open_fhs++;
|
cygheap->open_fhs++;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,9 +573,8 @@ fhandler_tty_slave::open (int flags, mode_t)
|
||||||
set_output_handle (to_master_local);
|
set_output_handle (to_master_local);
|
||||||
|
|
||||||
set_open_status ();
|
set_open_status ();
|
||||||
if (fhandler_console::open_fhs++ == 0 && !GetConsoleCP ()
|
if (cygheap->open_fhs++ == 0 && !GetConsoleCP () && !output_done_event
|
||||||
&& !output_done_event && wincap.pty_needs_alloc_console ()
|
&& wincap.pty_needs_alloc_console () && !GetProcessWindowStation ())
|
||||||
&& !GetProcessWindowStation ())
|
|
||||||
{
|
{
|
||||||
BOOL b;
|
BOOL b;
|
||||||
HWINSTA h = CreateWindowStation (NULL, 0, GENERIC_READ | GENERIC_WRITE, &sec_none_nih);
|
HWINSTA h = CreateWindowStation (NULL, 0, GENERIC_READ | GENERIC_WRITE, &sec_none_nih);
|
||||||
|
@ -610,7 +609,7 @@ out:
|
||||||
int
|
int
|
||||||
fhandler_tty_slave::close ()
|
fhandler_tty_slave::close ()
|
||||||
{
|
{
|
||||||
if (!--fhandler_console::open_fhs && myself->ctty == -1)
|
if (!--cygheap->open_fhs && myself->ctty == -1)
|
||||||
FreeConsole ();
|
FreeConsole ();
|
||||||
|
|
||||||
archetype->usecount--;
|
archetype->usecount--;
|
||||||
|
@ -620,13 +619,13 @@ fhandler_tty_slave::close ()
|
||||||
{
|
{
|
||||||
#ifdef DEBUGGING
|
#ifdef DEBUGGING
|
||||||
if (archetype->usecount < 0)
|
if (archetype->usecount < 0)
|
||||||
system_printf ("usecount %d", archetype->usecount);
|
system_printf ("error: usecount %d", archetype->usecount);
|
||||||
#endif
|
#endif
|
||||||
termios_printf ("just returning because archetype usecount is > 0");
|
termios_printf ("just returning because archetype usecount is != 0");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
termios_printf ("closing last open %s handle", pc.dev.name);
|
termios_printf ("closing last open %s handle", ttyname ());
|
||||||
return fhandler_tty_common::close ();
|
return fhandler_tty_common::close ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -914,7 +913,7 @@ fhandler_tty_slave::dup (fhandler_base *child)
|
||||||
*(fhandler_tty_slave *) child = *arch;
|
*(fhandler_tty_slave *) child = *arch;
|
||||||
child->usecount = 0;
|
child->usecount = 0;
|
||||||
arch->usecount++;
|
arch->usecount++;
|
||||||
fhandler_console::open_fhs++;
|
cygheap->open_fhs++;
|
||||||
report_tty_counts (child, "duped", "incremented ", "");
|
report_tty_counts (child, "duped", "incremented ", "");
|
||||||
myself->set_ctty (get_ttyp (), openflags, arch);
|
myself->set_ctty (get_ttyp (), openflags, arch);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1364,9 +1363,8 @@ fhandler_tty_common::set_close_on_exec (int val)
|
||||||
void
|
void
|
||||||
fhandler_tty_slave::fixup_after_fork (HANDLE parent)
|
fhandler_tty_slave::fixup_after_fork (HANDLE parent)
|
||||||
{
|
{
|
||||||
fhandler_console::open_fhs++;
|
// fhandler_tty_common::fixup_after_fork (parent);
|
||||||
termios_printf ("incremented open_fhs %d", fhandler_console::open_fhs);
|
report_tty_counts (this, "inherited", "", "");
|
||||||
fhandler_tty_common::fixup_after_fork (parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1411,7 +1409,7 @@ fhandler_tty_master::init_console ()
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
console->init (INVALID_HANDLE_VALUE, GENERIC_READ | GENERIC_WRITE, O_BINARY);
|
console->init (INVALID_HANDLE_VALUE, GENERIC_READ | GENERIC_WRITE, O_BINARY);
|
||||||
fhandler_console::open_fhs--; /* handled when individual fds are opened */
|
cygheap->open_fhs--; /* handled when individual fds are opened */
|
||||||
console->set_r_no_interrupt (1);
|
console->set_r_no_interrupt (1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -719,6 +719,8 @@ vfork ()
|
||||||
vf->ctty = myself->ctty;
|
vf->ctty = myself->ctty;
|
||||||
vf->sid = myself->sid;
|
vf->sid = myself->sid;
|
||||||
vf->pgid = myself->pgid;
|
vf->pgid = myself->pgid;
|
||||||
|
vf->fhctty = cygheap->ctty;
|
||||||
|
vf->open_fhs = cygheap->open_fhs;
|
||||||
int res = cygheap->fdtab.vfork_child_dup () ? 0 : -1;
|
int res = cygheap->fdtab.vfork_child_dup () ? 0 : -1;
|
||||||
debug_printf ("%d = vfork()", res);
|
debug_printf ("%d = vfork()", res);
|
||||||
call_signal_handler_now (); // FIXME: racy
|
call_signal_handler_now (); // FIXME: racy
|
||||||
|
@ -737,6 +739,20 @@ vfork ()
|
||||||
myself->ctty = vf->ctty;
|
myself->ctty = vf->ctty;
|
||||||
myself->sid = vf->sid;
|
myself->sid = vf->sid;
|
||||||
myself->pgid = vf->pgid;
|
myself->pgid = vf->pgid;
|
||||||
|
termios_printf ("cygheap->ctty %p, vf->fhctty %p", cygheap->ctty, vf->fhctty);
|
||||||
|
if (cygheap->ctty != vf->fhctty)
|
||||||
|
{
|
||||||
|
vf->fhctty->close ();
|
||||||
|
if (vf->pid <= 0)
|
||||||
|
{
|
||||||
|
if (vf->ctty)
|
||||||
|
vf->fhctty->close ();
|
||||||
|
cygheap->ctty = vf->fhctty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vf->pid <= 0)
|
||||||
|
cygheap->open_fhs = vf->open_fhs;
|
||||||
|
|
||||||
if (vf->pid < 0)
|
if (vf->pid < 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -59,6 +59,8 @@ class vfork_save
|
||||||
int ctty;
|
int ctty;
|
||||||
pid_t sid;
|
pid_t sid;
|
||||||
pid_t pgid;
|
pid_t pgid;
|
||||||
|
class fhandler_tty_slave *fhctty;
|
||||||
|
int open_fhs;
|
||||||
int is_active () { return pid < 0; }
|
int is_active () { return pid < 0; }
|
||||||
void restore_pid (int val)
|
void restore_pid (int val)
|
||||||
{
|
{
|
||||||
|
|
|
@ -257,7 +257,7 @@ pinfo::set_acl()
|
||||||
void
|
void
|
||||||
_pinfo::set_ctty (tty_min *tc, int flags, fhandler_tty_slave *arch)
|
_pinfo::set_ctty (tty_min *tc, int flags, fhandler_tty_slave *arch)
|
||||||
{
|
{
|
||||||
debug_printf ("ctty %d", ctty);
|
debug_printf ("checking if /dev/tty%d differs from input", ctty);
|
||||||
if ((ctty < 0 || ctty == tc->ntty) && !(flags & O_NOCTTY))
|
if ((ctty < 0 || ctty == tc->ntty) && !(flags & O_NOCTTY))
|
||||||
{
|
{
|
||||||
ctty = tc->ntty;
|
ctty = tc->ntty;
|
||||||
|
@ -292,7 +292,7 @@ _pinfo::set_ctty (tty_min *tc, int flags, fhandler_tty_slave *arch)
|
||||||
if (arch)
|
if (arch)
|
||||||
{
|
{
|
||||||
arch->usecount++;
|
arch->usecount++;
|
||||||
fhandler_console::open_fhs++;
|
cygheap->open_fhs++;
|
||||||
report_tty_counts (cygheap->ctty, "ctty", "incremented ", "");
|
report_tty_counts (cygheap->ctty, "ctty", "incremented ", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,7 @@ close_all_files (void)
|
||||||
{
|
{
|
||||||
debug_printf ("closing ctty");
|
debug_printf ("closing ctty");
|
||||||
cygheap->ctty->close ();
|
cygheap->ctty->close ();
|
||||||
|
cygheap->ctty = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "close_all_files");
|
ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "close_all_files");
|
||||||
|
@ -320,7 +321,7 @@ setsid (void)
|
||||||
syscall_printf ("hmm. pgid %d pid %d", myself->pgid, myself->pid);
|
syscall_printf ("hmm. pgid %d pid %d", myself->pgid, myself->pid);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (myself->ctty >= 0 && fhandler_console::open_fhs <= 0)
|
if (myself->ctty >= 0 && cygheap->open_fhs <= 0)
|
||||||
{
|
{
|
||||||
syscall_printf ("freeing console");
|
syscall_printf ("freeing console");
|
||||||
FreeConsole ();
|
FreeConsole ();
|
||||||
|
@ -329,7 +330,7 @@ setsid (void)
|
||||||
myself->sid = getpid ();
|
myself->sid = getpid ();
|
||||||
myself->pgid = getpid ();
|
myself->pgid = getpid ();
|
||||||
syscall_printf ("sid %d, pgid %d, ctty %d, open_fhs %d", myself->sid,
|
syscall_printf ("sid %d, pgid %d, ctty %d, open_fhs %d", myself->sid,
|
||||||
myself->pgid, myself->ctty, fhandler_console::open_fhs);
|
myself->pgid, myself->ctty, cygheap->open_fhs);
|
||||||
if (cygheap->ctty)
|
if (cygheap->ctty)
|
||||||
{
|
{
|
||||||
cygheap->ctty->close ();
|
cygheap->ctty->close ();
|
||||||
|
|
Loading…
Reference in New Issue