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-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>
* fhandler.h (fhandler_tty_slave::archetype): Make public.
&& (set_process_privilege (SE_CREATE_GLOBAL_NAME, true) >= 0
|| GetLastError () == ERROR_NO_SUCH_PRIVILEGE)
? "Global\\" : "");
- if (cygheap->ctty)
- {
- fhandler_console::open_fhs++;
- report_tty_counts (cygheap->ctty, "inherited", "incremented ", "unchanged ");
- }
}
/* Copyright (C) 1997, 2000 DJ Delorie */
struct sigaction *sigs;
fhandler_tty_slave *ctty; /* Current tty */
+ int open_fhs;
};
#define CYGHEAPSIZE (sizeof (init_cygheap) + (20000 * sizeof (fhandler_union)) + (5 * 65536))
void
dtable::delete_archetype (fhandler_base *fh)
{
- for (unsigned i = 0; i < narchetypes; i++)
+ for (unsigned i = 0; i < farchetype; 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)
archetypes[i] = archetypes[farchetype];
break;
{
fh->clear_readahead ();
if (fh->get_close_on_exec ())
- release (i);
+ {
+ if (fh->archetype)
+ fh->close ();
+ release (i);
+ }
else
{
fh->fixup_after_exec (parent);
if (cygheap->ctty)
{
cygheap->ctty->usecount++;
- fhandler_console::open_fhs++;
+ cygheap->open_fhs++;
report_tty_counts (cygheap->ctty, "vfork dup", "incremented ", "");
}
fds_on_hold = NULL;
cfree (deleteme);
- if (cygheap->ctty)
- cygheap->ctty->close ();
-
ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "restore");
return;
}
fhandler_base **saveme = fds;
fds = fds_on_hold;
- int old_open_fhs = fhandler_console::open_fhs;
fhandler_base *fh;
for (int i = 0; i < (int) size; i++)
if ((fh = fds[i]) != NULL)
}
}
- fhandler_console::open_fhs = old_open_fhs;
- if (cygheap->ctty)
- cygheap->ctty->close ();
-
fds = saveme;
cfree (fds_on_hold);
fds_on_hold = NULL;
void set_cursor_maybe ();
public:
- static int open_fhs;
-
fhandler_console ();
fhandler_console* is_console () { return this; }
#define report_tty_counts(fh, call, fhs_op, use_op) \
termios_printf ("%s %s, %sopen_fhs %d, %susecount %d",\
fh->ttyname (), call,\
- fhs_op, fhandler_console::open_fhs,\
+ fhs_op, cygheap->open_fhs,\
use_op, ((fhandler_tty_slave *) fh)->archetype->usecount);
typedef union
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.
Returns a pointer to shared_console_info. */
tty_min *
TTYCLEARF (RSTCONS);
set_open_status ();
- open_fhs++;
- debug_printf ("incremented open_fhs, now %d", open_fhs);
- debug_printf ("opened conin$ %p, conout$ %p",
- get_io_handle (), get_output_handle ());
+ cygheap->open_fhs++;
+ debug_printf ("incremented open_fhs, now %d", cygheap->open_fhs);
+ debug_printf ("opened conin$ %p, conout$ %p", get_io_handle (),
+ get_output_handle ());
return 1;
}
CloseHandle (get_output_handle ());
set_io_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)
{
- syscall_printf ("open_fhs %d, freeing console %p",
- fhandler_console::open_fhs, myself->ctty);
+ syscall_printf ("open_fhs %d, freeing console %p", cygheap->open_fhs,
+ myself->ctty);
FreeConsole ();
}
- debug_printf ("decremented open_fhs, now %d", open_fhs);
+ debug_printf ("decremented open_fhs, now %d", cygheap->open_fhs);
return 0;
}
if (arch)
{
*this = *(fhandler_tty_slave *) arch;
- termios_printf ("copied tty fhandler from cygheap");
- fhandler_console::open_fhs++;
+ termios_printf ("copied tty fhandler archetype");
+ cygheap->open_fhs++;
goto out;
}
set_output_handle (to_master_local);
set_open_status ();
- if (fhandler_console::open_fhs++ == 0 && !GetConsoleCP ()
- && !output_done_event && wincap.pty_needs_alloc_console ()
- && !GetProcessWindowStation ())
+ if (cygheap->open_fhs++ == 0 && !GetConsoleCP () && !output_done_event
+ && wincap.pty_needs_alloc_console () && !GetProcessWindowStation ())
{
BOOL b;
HWINSTA h = CreateWindowStation (NULL, 0, GENERIC_READ | GENERIC_WRITE, &sec_none_nih);
int
fhandler_tty_slave::close ()
{
- if (!--fhandler_console::open_fhs && myself->ctty == -1)
+ if (!--cygheap->open_fhs && myself->ctty == -1)
FreeConsole ();
archetype->usecount--;
{
#ifdef DEBUGGING
if (archetype->usecount < 0)
- system_printf ("usecount %d", archetype->usecount);
+ system_printf ("error: usecount %d", archetype->usecount);
#endif
- termios_printf ("just returning because archetype usecount is > 0");
+ termios_printf ("just returning because archetype usecount is != 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 ();
}
*(fhandler_tty_slave *) child = *arch;
child->usecount = 0;
arch->usecount++;
- fhandler_console::open_fhs++;
+ cygheap->open_fhs++;
report_tty_counts (child, "duped", "incremented ", "");
myself->set_ctty (get_ttyp (), openflags, arch);
return 0;
void
fhandler_tty_slave::fixup_after_fork (HANDLE parent)
{
- fhandler_console::open_fhs++;
- termios_printf ("incremented open_fhs %d", fhandler_console::open_fhs);
- fhandler_tty_common::fixup_after_fork (parent);
+ // fhandler_tty_common::fixup_after_fork (parent);
+ report_tty_counts (this, "inherited", "", "");
}
void
return -1;
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);
return 0;
}
vf->ctty = myself->ctty;
vf->sid = myself->sid;
vf->pgid = myself->pgid;
+ vf->fhctty = cygheap->ctty;
+ vf->open_fhs = cygheap->open_fhs;
int res = cygheap->fdtab.vfork_child_dup () ? 0 : -1;
debug_printf ("%d = vfork()", res);
- call_signal_handler_now (); // FIXME: racy
+ call_signal_handler_now (); // FIXME: racy
vf->tls = _my_tls;
return res;
}
myself->ctty = vf->ctty;
myself->sid = vf->sid;
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)
{
int ctty;
pid_t sid;
pid_t pgid;
+ class fhandler_tty_slave *fhctty;
+ int open_fhs;
int is_active () { return pid < 0; }
void restore_pid (int val)
{
void
_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))
{
ctty = tc->ntty;
if (arch)
{
arch->usecount++;
- fhandler_console::open_fhs++;
+ cygheap->open_fhs++;
report_tty_counts (cygheap->ctty, "ctty", "incremented ", "");
}
}
{
debug_printf ("closing ctty");
cygheap->ctty->close ();
+ cygheap->ctty = NULL;
}
ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "close_all_files");
syscall_printf ("hmm. pgid %d pid %d", myself->pgid, myself->pid);
else
{
- if (myself->ctty >= 0 && fhandler_console::open_fhs <= 0)
+ if (myself->ctty >= 0 && cygheap->open_fhs <= 0)
{
syscall_printf ("freeing console");
FreeConsole ();
myself->sid = getpid ();
myself->pgid = getpid ();
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)
{
cygheap->ctty->close ();