Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2004-01-24 02:05:33 +0300
committerChristopher Faylor <me@cgf.cx>2004-01-24 02:05:33 +0300
commitf723909038afc7657b5a19c48d64458ad0dd18d8 (patch)
tree42581fecc70aca8fff333f8e7808fab4400a6b2b /winsup/cygwin/pipe.cc
parent7dddf53f5caee354852156ce552859c0bc81a3c7 (diff)
* configure.in: Remove NEWVFORK default.
* configure: Regenerate. * dcrt0.cc: Conditionalize vfork stuff throughout. * dtable.cc: Ditto. * perthread.h: Ditto. * pipe.cc (fhandler_pipe::close): Ditto. * spawn.cc (spawnve): Ditto. * syscalls.cc (setsid): Ditto. * exceptions.cc (sigpacket::process): Use macro to refer to vfork pid. * debug.cc (verify_handle): Define new function. * debug.h (VerifyHandle): Define new macro. (verify_handle): Declare new function * fhandler.cc (fhandler_base::dup): Verify that dup'ed handle is not supposed to be in use. (fhandler_base::set_inheritance): Ditto. (fhandler_base::fork_fixup): Ditto. * fhandler_socket.cc (fhandler_socket::dup): Ditto. * fhandler_tty.cc (fhandler_tty_slave::open): Ditto. * net.cc (set_socket_inheritance): Ditto. * pinfo.cc (pinfo_fixup_after_exec): Ditto. * sigproc.cc (proc_subproc): Ditto. (sig_send): Ditto. * spawn.cc (spawn_guts): Ditto. * thread.cc (pthread::init_mainthread): Ditto. * pipe.cc (fhandler_pipe::close): Close read_state with ForceCloseHandle since it was protected. (fhandler_pipe::fixup_after_exec): Protect read_state handle. (fhandler_pipe::dup): Correctly close open handles on error condition. Verify that dup'ed handle is not supposed to be in use. (fhandler_pipe::create): Protect read_state.
Diffstat (limited to 'winsup/cygwin/pipe.cc')
-rw-r--r--winsup/cygwin/pipe.cc49
1 files changed, 39 insertions, 10 deletions
diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc
index abc9a81a3..82313c492 100644
--- a/winsup/cygwin/pipe.cc
+++ b/winsup/cygwin/pipe.cc
@@ -89,11 +89,15 @@ fhandler_pipe::close ()
CloseHandle (guard);
if (writepipe_exists)
CloseHandle (writepipe_exists);
+#ifndef NEWVFORK
+ if (read_state)
+#else
// FIXME is this vfork_cleanup test right? Is it responsible for some of
// the strange pipe behavior that has been reported in the cygwin mailing
// list?
if (read_state && !cygheap->fdtab.in_vfork_cleanup ())
- CloseHandle (read_state);
+#endif
+ ForceCloseHandle (read_state);
if (get_handle ())
{
CloseHandle (get_handle ());
@@ -122,7 +126,10 @@ void
fhandler_pipe::fixup_after_exec (HANDLE parent)
{
if (read_state)
- read_state = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL);
+ {
+ read_state = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL);
+ ProtectHandle (read_state);
+ }
}
void
@@ -139,15 +146,17 @@ fhandler_pipe::fixup_after_fork (HANDLE parent)
int
fhandler_pipe::dup (fhandler_base *child)
{
+ int res = -1;
+ fhandler_pipe *ftp = (fhandler_pipe *) child;
+ ftp->guard = ftp->writepipe_exists = ftp->read_state = NULL;
+
if (get_handle ())
{
- int res = fhandler_base::dup (child);
+ res = fhandler_base::dup (child);
if (res)
- return res;
+ goto err;
}
- fhandler_pipe *ftp = (fhandler_pipe *) child;
-
/* FIXME: This leaks handles in the failing condition */
if (guard == NULL)
ftp->guard = NULL;
@@ -155,7 +164,7 @@ fhandler_pipe::dup (fhandler_base *child)
DUPLICATE_SAME_ACCESS))
{
debug_printf ("couldn't duplicate guard %p, %E", guard);
- return -1;
+ goto err;
}
if (writepipe_exists == NULL)
@@ -165,7 +174,7 @@ fhandler_pipe::dup (fhandler_base *child)
DUPLICATE_SAME_ACCESS))
{
debug_printf ("couldn't duplicate writepipe_exists %p, %E", writepipe_exists);
- return -1;
+ goto err;
}
if (read_state == NULL)
@@ -175,12 +184,31 @@ fhandler_pipe::dup (fhandler_base *child)
DUPLICATE_SAME_ACCESS))
{
debug_printf ("couldn't duplicate read_state %p, %E", writepipe_exists);
- return -1;
+ goto err;
}
+ res = 0;
+ goto out;
+
+err:
+ if (!ftp->guard)
+ CloseHandle (ftp->guard);
+ if (!ftp->writepipe_exists)
+ CloseHandle (ftp->writepipe_exists);
+ if (!ftp->read_state)
+ CloseHandle (ftp->read_state);
+ goto leave;
+
+out:
ftp->id = id;
ftp->orig_pid = orig_pid;
- return 0;
+ VerifyHandle (ftp->guard);
+ VerifyHandle (ftp->writepipe_exists);
+ VerifyHandle (ftp->read_state);
+
+leave:
+ debug_printf ("res %d", res);
+ return res;
}
int
@@ -208,6 +236,7 @@ fhandler_pipe::create (fhandler_pipe *fhs[2], unsigned psize, int mode, bool fif
fhs[0]->read_state = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL);
fhs[0]->set_need_fork_fixup ();
+ ProtectHandle1 (fhs[0]->read_state, read_state);
res = 0;
fhs[0]->create_guard (sa);