aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2003-12-27 17:41:17 +0000
committerChristopher Faylor <me@cgf.cx>2003-12-27 17:41:17 +0000
commite97377932b06f0993df95c7c7877474ec20ff74d (patch)
treee06f5299ce91c509ac8a34d9aa13226e5206f5e3
parentfe861ce9344d7577a909fc2878b2e61483bf6107 (diff)
downloadnewlib-e97377932b06f0993df95c7c7877474ec20ff74d.zip
newlib-e97377932b06f0993df95c7c7877474ec20ff74d.tar.gz
newlib-e97377932b06f0993df95c7c7877474ec20ff74d.tar.bz2
* fhandler.h (fhandler_tty_slave::archetype): Make public.
(report_tty_counts): New macro. Use throughout for reporting tty use counts. * dtable.cc (dtable::vfork_child_dup): Add debugging output for usecount increment. Increment open_fhs if appropriate. (dtable::vfork_parent_restore): "Close" artificially bumped ctty. (dtable::vfork_child_fixup): Close ctty since it was bumped prior to vfork. Save open_fhs around close since the closing of these handles has no effect on the console. * fhandler_tty.cc (fhandler_tty_slave::open): Reorganize calls to allow for easier tracking of usecount modification. (fhandler_tty_slave::open): Ditto.
-rw-r--r--winsup/cygwin/ChangeLog15
-rw-r--r--winsup/cygwin/cygheap.cc4
-rw-r--r--winsup/cygwin/dtable.cc15
-rw-r--r--winsup/cygwin/fhandler.h8
-rw-r--r--winsup/cygwin/fhandler_tty.cc18
-rw-r--r--winsup/cygwin/pinfo.cc3
6 files changed, 47 insertions, 16 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 3452248..b838327 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,18 @@
+2003-12-27 Christopher Faylor <cgf@redhat.com>
+
+ * fhandler.h (fhandler_tty_slave::archetype): Make public.
+ (report_tty_counts): New macro. Use throughout for reporting tty use
+ counts.
+ * dtable.cc (dtable::vfork_child_dup): Add debugging output for
+ usecount increment. Increment open_fhs if appropriate.
+ (dtable::vfork_parent_restore): "Close" artificially bumped ctty.
+ (dtable::vfork_child_fixup): Close ctty since it was bumped prior to
+ vfork. Save open_fhs around close since the closing of these handles
+ has no effect on the console.
+ * fhandler_tty.cc (fhandler_tty_slave::open): Reorganize calls to allow
+ for easier tracking of usecount modification.
+ (fhandler_tty_slave::open): Ditto.
+
2003-12-26 Christopher Faylor <cgf@redhat.com>
* syscalls.cc (close_all_files): Simplify logic around closing ctty.
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc
index 16a95f4..54b645f 100644
--- a/winsup/cygwin/cygheap.cc
+++ b/winsup/cygwin/cygheap.cc
@@ -215,9 +215,7 @@ cygheap_init ()
if (cygheap->ctty)
{
fhandler_console::open_fhs++;
- debug_printf ("tty%d, open_fhs %d, arch usecount %d",
- cygheap->ctty->get_ttyp ()->ntty,
- fhandler_console::open_fhs, cygheap->ctty->usecount);
+ report_tty_counts (cygheap->ctty, "inherited", "incremented ", "unchanged ");
}
}
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index b4c5db0..a7095c5 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -31,6 +31,7 @@ details. */
#include "dtable.h"
#include "cygheap.h"
#include "ntdll.h"
+#include "tty.h"
static const NO_COPY DWORD std_consts[] = {STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
STD_ERROR_HANDLE};
@@ -701,7 +702,11 @@ dtable::vfork_child_dup ()
/* Remove impersonation */
cygheap->user.deimpersonate ();
if (cygheap->ctty)
- cygheap->ctty->usecount++;
+ {
+ cygheap->ctty->usecount++;
+ fhandler_console::open_fhs++;
+ report_tty_counts (cygheap->ctty, "vfork dup", "incremented ", "");
+ }
for (size_t i = 0; i < size; i++)
if (not_open (i))
@@ -737,6 +742,9 @@ dtable::vfork_parent_restore ()
fds_on_hold = NULL;
cfree (deleteme);
+ if (cygheap->ctty)
+ cygheap->ctty->close ();
+
ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "restore");
return;
}
@@ -750,6 +758,7 @@ dtable::vfork_child_fixup ()
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)
@@ -764,6 +773,10 @@ dtable::vfork_child_fixup ()
}
}
+ fhandler_console::open_fhs = old_open_fhs;
+ if (cygheap->ctty)
+ cygheap->ctty->close ();
+
fds = saveme;
cfree (fds_on_hold);
fds_on_hold = NULL;
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 5cbf387..a064e24 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -122,9 +122,9 @@ class fhandler_base
DWORD fs_flags;
HANDLE read_state;
path_conv pc;
- class fhandler_base *archetype;
public:
+ class fhandler_base *archetype;
int usecount;
void set_name (path_conv &pc);
@@ -1194,6 +1194,12 @@ struct fhandler_nodevice: public fhandler_base
// int __stdcall fstat (struct __stat64 *buf, path_conv *);
};
+#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,\
+ use_op, ((fhandler_tty_slave *) fh)->archetype->usecount);
+
typedef union
{
char __base[sizeof (fhandler_base)];
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index ff1d48f..69d03a9 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -601,9 +601,8 @@ fhandler_tty_slave::open (int flags, mode_t)
out:
usecount = 0;
archetype->usecount++;
+ report_tty_counts (this, "opened", "incremented ", "");
myself->set_ctty (get_ttyp (), flags, arch);
- termios_printf ("%s opened, incremented open_fhs %d, archetype usecount %d",
- pc.dev.name, fhandler_console::open_fhs, archetype->usecount);
return 1;
}
@@ -613,9 +612,11 @@ fhandler_tty_slave::close ()
{
if (!--fhandler_console::open_fhs && myself->ctty == -1)
FreeConsole ();
- termios_printf ("decremented open_fhs %d, archetype usecount %d",
- fhandler_console::open_fhs, archetype->usecount);
- if (--archetype->usecount)
+
+ archetype->usecount--;
+ report_tty_counts (this, "closed", "decremented ", "");
+
+ if (archetype->usecount)
{
#ifdef DEBUGGING
if (archetype->usecount < 0)
@@ -909,14 +910,13 @@ fhandler_tty_slave::read (void *ptr, size_t& len)
int
fhandler_tty_slave::dup (fhandler_base *child)
{
- fhandler_console::open_fhs++;
fhandler_tty_slave *arch = (fhandler_tty_slave *) archetype;
*(fhandler_tty_slave *) child = *arch;
- arch->usecount++;
child->usecount = 0;
+ arch->usecount++;
+ fhandler_console::open_fhs++;
+ report_tty_counts (child, "duped", "incremented ", "");
myself->set_ctty (get_ttyp (), openflags, arch);
- termios_printf ("incremented open_fhs %d, archetype usecount %d",
- fhandler_console::open_fhs, archetype->usecount);
return 0;
}
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index 92a9ea9..0472145 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -293,8 +293,7 @@ _pinfo::set_ctty (tty_min *tc, int flags, fhandler_tty_slave *arch)
{
arch->usecount++;
fhandler_console::open_fhs++;
- debug_printf ("tty%d, open_fhs %d, arch usecount %d", tc->ntty,
- fhandler_console::open_fhs, arch->usecount);
+ report_tty_counts (cygheap->ctty, "ctty", "incremented ", "");
}
}
}