From ad6c2e9137ba53a0c5248b7e30c15c5843e473f8 Mon Sep 17 00:00:00 2001 From: "William A. Rowe Jr" Date: Wed, 17 Apr 2002 16:39:12 +0000 Subject: [PATCH] Experimental patch that may mitigate (but not eliminate) the errors in [crit] (32538)An operation was attempted on something that is not a socket. : Parent: WSADuplicateSocket failed for socket ... if the particular stacks' bug is that it won't associate a handle as a socket if that handle was duped with DuplicateHandle(). Other bugs with unimplemented WSADuplicateSocket are not addressed by this patch. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@94682 13f79535-47bb-0310-9956-ffa450edef68 --- server/mpm/winnt/mpm_winnt.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index 4ece337118..34ca240e54 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -527,15 +527,32 @@ static int set_listeners_noninheritable(apr_pool_t *p) for (lr = ap_listeners; lr; lr = lr->next) { apr_os_sock_get(&nsd,lr->sd); - if (!DuplicateHandle(hProcess, (HANDLE) nsd, hProcess, &dup, - 0, FALSE, DUPLICATE_SAME_ACCESS)) { - ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_os_error(), ap_server_conf, - "set_listeners_noninheritable: DuplicateHandle failed."); + if (osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { + if (!DuplicateHandle(hProcess, (HANDLE) nsd, hProcess, &dup, + 0, FALSE, DUPLICATE_SAME_ACCESS)) { + ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_os_error(), ap_server_conf, + "set_listeners_noninheritable: DuplicateHandle failed."); + } + else { + closesocket(nsd); + nsd = (SOCKET) dup; + apr_os_sock_put(&lr->sd, &nsd, p); + } } else { - closesocket(nsd); - nsd = (SOCKET) dup; - apr_os_sock_put(&lr->sd, &nsd, p); + /* A different approach. Many users report errors such as + * (32538)An operation was attempted on something that is not + * a socket. : Parent: WSADuplicateSocket failed... + * + * This appears that the duplicated handle is no longer recognized + * as a socket handle. SetHandleInformation should overcome that + * problem by not altering the handle identifier. But this won't + * work on 9x - it's unsupported. + */ + if (!SetHandleInformation(nsd, HANDLE_FLAG_INHERIT, 0)) { + ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_os_error(), ap_server_conf, + "set_listeners_noninheritable: SetHandleInformation failed."); + } } } -- 2.40.0