aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2006-07-11 08:59:02 +0000
committerCorinna Vinschen <corinna@vinschen.de>2006-07-11 08:59:02 +0000
commit7e6248ec083f9339cb09e25c8f5a111ce415d82a (patch)
treea97023293463d5320935c3c6d060a0f927c3f93b
parent5a7054761c402d39d2447ab56c2f78acb94f0ec3 (diff)
downloadnewlib-7e6248ec083f9339cb09e25c8f5a111ce415d82a.zip
newlib-7e6248ec083f9339cb09e25c8f5a111ce415d82a.tar.gz
newlib-7e6248ec083f9339cb09e25c8f5a111ce415d82a.tar.bz2
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly. (fhandler_socket::fixup_after_exec): Drop misguided attempt to handle close_on_exec here. (fhandler_socket::dup): Call fixup_after_fork with NULL parent. Add comment. (fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
-rw-r--r--winsup/cygwin/ChangeLog10
-rw-r--r--winsup/cygwin/fhandler_socket.cc16
2 files changed, 20 insertions, 6 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 4990f71..4f1a766 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,13 @@
+2006-07-11 Corinna Vinschen <corinna@vinschen.de>
+
+ * fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
+ wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
+ (fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
+ close_on_exec here.
+ (fhandler_socket::dup): Call fixup_after_fork with NULL parent.
+ Add comment.
+ (fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
+
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc
index b71f8bb..fa661fb 100644
--- a/winsup/cygwin/fhandler_socket.cc
+++ b/winsup/cygwin/fhandler_socket.cc
@@ -654,6 +654,11 @@ fhandler_socket::fixup_after_fork (HANDLE parent)
set_io_handle ((HANDLE) new_sock);
}
+ if (parent) /* fork, not exec or dup */
+ {
+ fork_fixup (parent, wsock_mtx, "wsock_mtx");
+ fork_fixup (parent, wsock_evt, "wsock_evt");
+ }
}
void
@@ -661,11 +666,6 @@ fhandler_socket::fixup_after_exec ()
{
if (!close_on_exec ())
fixup_after_fork (NULL);
- else
- {
- CloseHandle (wsock_evt);
- CloseHandle (wsock_mtx);
- }
}
int
@@ -723,7 +723,9 @@ fhandler_socket::dup (fhandler_base *child)
cygheap->user.reimpersonate ();
if (!WSAGetLastError ())
{
- fhs->fixup_after_fork (hMainProc);
+ /* Call with NULL parent, otherwise wsock_mtx and wsock_evt are
+ duplicated again with wrong close_on_exec settings. */
+ fhs->fixup_after_fork (NULL);
if (fhs->get_io_handle() != (HANDLE) INVALID_SOCKET)
{
cygheap->fdtab.inc_need_fixup_before ();
@@ -1637,6 +1639,8 @@ fhandler_socket::fcntl (int cmd, void *arg)
void
fhandler_socket::set_close_on_exec (bool val)
{
+ set_no_inheritance (wsock_mtx, val);
+ set_no_inheritance (wsock_evt, val);
close_on_exec (val);
debug_printf ("set close_on_exec for %s to %d", get_name (), val);
}