summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/fhandler.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2004-01-23 23:05:33 +0000
committerChristopher Faylor <me@cgf.cx>2004-01-23 23:05:33 +0000
commitf723909038afc7657b5a19c48d64458ad0dd18d8 (patch)
tree42581fecc70aca8fff333f8e7808fab4400a6b2b /winsup/cygwin/fhandler.cc
parent7dddf53f5caee354852156ce552859c0bc81a3c7 (diff)
downloadcygnal-f723909038afc7657b5a19c48d64458ad0dd18d8.tar.gz
cygnal-f723909038afc7657b5a19c48d64458ad0dd18d8.tar.bz2
cygnal-f723909038afc7657b5a19c48d64458ad0dd18d8.zip
* 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/fhandler.cc')
-rw-r--r--winsup/cygwin/fhandler.cc16
1 files changed, 7 insertions, 9 deletions
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index 0aad893a3..d5619bd63 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -1044,6 +1044,7 @@ fhandler_base::dup (fhandler_base *child)
return -1;
}
+ VerifyHandle (nh);
child->set_io_handle (nh);
}
return 0;
@@ -1209,17 +1210,17 @@ fhandler_dev_null::dump (void)
void
fhandler_base::set_inheritance (HANDLE &h, int not_inheriting)
{
-#ifdef DEBUGGING_AND_FDS_PROTECTED
HANDLE oh = h;
-#endif
/* Note that we could use SetHandleInformation here but it is not available
on all platforms. Test cases seem to indicate that using DuplicateHandle
in this fashion does not actually close the original handle, which is
what we want. If this changes in the future, we may be forced to use
SetHandleInformation on newer OS's */
- if (!DuplicateHandle (hMainProc, h, hMainProc, &h, 0, !not_inheriting,
+ if (!DuplicateHandle (hMainProc, oh, hMainProc, &h, 0, !not_inheriting,
DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
debug_printf ("DuplicateHandle failed, %E");
+ if (oh != h)
+ VerifyHandle (h);
#ifdef DEBUGGING_AND_FDS_PROTECTED
if (h)
setclexec (oh, h, not_inheriting);
@@ -1229,17 +1230,14 @@ fhandler_base::set_inheritance (HANDLE &h, int not_inheriting)
void
fhandler_base::fork_fixup (HANDLE parent, HANDLE &h, const char *name)
{
+ HANDLE oh = h;
if (/* !is_socket () && */ !get_close_on_exec ())
debug_printf ("handle %p already opened", h);
else if (!DuplicateHandle (parent, h, hMainProc, &h, 0, !get_close_on_exec (),
DUPLICATE_SAME_ACCESS))
system_printf ("%s - %E, handle %s<%p>", get_name (), name, h);
-#ifdef DEBUGGING_AND_FDS_PROTECTED
- else if (get_close_on_exec ())
- ProtectHandle (h); /* would have to be fancier than this */
- else
- /* ProtectHandleINH (h) */; /* Should already be protected */
-#endif
+ else if (oh != h)
+ VerifyHandle (h);
}
void