diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2009-11-17 13:43:01 +0300 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2009-11-17 13:43:01 +0300 |
commit | b14f53a8ec619146e20cae8831dec4a8d9aaf883 (patch) | |
tree | 029928c686817a409f1665db3eb5a381f411f819 /winsup/cygwin/fork.cc | |
parent | 88242190ec6f016a5a7956bd20a844dd38e436e6 (diff) |
Reintegrate socket duplication via WSADuplicateSocket/WSASocket.
* autoload.cc (WSADuplicateSocketW): Define.
(WSASocketW): Define.
* dtable.cc (dtable::release): Call dec_need_fixup_before if necessary.
(dtable::fixup_before_fork): New function.
(dtable::fixup_before_exec): New function.
* dtable.h (class dtable): Add member cnt_need_fixup_before. Add
declarations for above new functions.
(dtable::dec_need_fixup_before): New inline method.
(dtable::inc_need_fixup_before): New inline method.
(dtable::need_fixup_before): New inline method.
* fhandler.h (fhandler_base::fixup_before_fork_exec): New virtual
method.
(fhandler_base::need_fixup_before): New virtual method.
(class fhandler_socket): Add member prot_info_ptr.
(fhandler_socket::init_fixup_before): Declare.
(fhandler_socket::need_fixup_before): New inline method.
(fhandler_socket::fixup_before_fork_exec): Declare.
(fhandler_socket::fixup_after_exec): Declare.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Initialize
prot_info_ptr to NULL.
(fhandler_socket::~fhandler_socket): Free prot_info_ptr conditionally.
(fhandler_socket::init_fixup_before): New method.
(fhandler_socket::fixup_before_fork_exec): Ditto.
(fhandler_socket::fixup_after_fork): Use WSASocketW to duplicate
socket if necessary.
(fhandler_socket::fixup_after_exec): New method.
(fhandler_socket::dup): Use fixup_before_fork_exec/fixup_after_fork
to duplicate socket if necessary.
* fork.cc (frok::parent): Start child suspended if some fhandler
needs fixup before fork. If so, call dtable::fixup_before_fork after
CreateProcess and resume child.
* net.cc (fdsock): Try to find out if socket needs fixup before and
initialize socket accordingly. Add HUGE comment to explain what happens
and why.
* spawn.cc (spawn_guts): Start child suspended if some fhandler needs
fixup before exec. If so, call dtable::fixup_before_exec after
CreateProcess.
Diffstat (limited to 'winsup/cygwin/fork.cc')
-rw-r--r-- | winsup/cygwin/fork.cc | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc index ac2e9ca5e..ea162519f 100644 --- a/winsup/cygwin/fork.cc +++ b/winsup/cygwin/fork.cc @@ -302,6 +302,13 @@ frok::parent (volatile char * volatile stack_here) else c_flags |= DETACHED_PROCESS; + /* Some file types (currently only sockets) need extra effort in the + parent after CreateProcess and before copying the datastructures + to the child. So we have to start the child in suspend state, + unfortunately, to avoid a race condition. */ + if (cygheap->fdtab.need_fixup_before ()) + c_flags |= CREATE_SUSPENDED; + /* Remember if we need to load dynamically linked dlls. We do this here so that this information will be available in the parent and, when the stack is copied, in the child. */ @@ -369,6 +376,12 @@ frok::parent (volatile char * volatile stack_here) goto cleanup; } + if (cygheap->fdtab.need_fixup_before ()) + { + cygheap->fdtab.fixup_before_fork (pi.dwProcessId); + ResumeThread (pi.hThread); + } + CloseHandle (pi.hThread); /* Protect the handle but name it similarly to the way it will |