From cc75cfcf4f608dae2c5fd44a94255528765e3d6f Mon Sep 17 00:00:00 2001 From: "William A. Rowe Jr" Date: Wed, 3 Jul 2002 00:16:55 +0000 Subject: [PATCH] Have inherit_set/unset work correctly. Sockets can't do this, so punt. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@63556 13f79535-47bb-0310-9956-ffa450edef68 --- include/arch/win32/inherit.h | 41 ++++++++++++++++++++++++++++++++---- network_io/win32/sockets.c | 26 +++++++++++++++++++++-- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/include/arch/win32/inherit.h b/include/arch/win32/inherit.h index 577b9788e09..9fb3aa7f998 100644 --- a/include/arch/win32/inherit.h +++ b/include/arch/win32/inherit.h @@ -62,23 +62,56 @@ #define APR_IMPLEMENT_INHERIT_SET(name, flag, pool, cleanup) \ APR_DECLARE(void) apr_##name##_inherit_set(apr_##name##_t *name) \ { \ - return; \ + IF_WIN_OS_IS_UNICODE \ + { \ + if (!SetHandleInformation(name->filehand, \ + HANDLE_FLAG_INHERIT, \ + HANDLE_FLAG_INHERIT)) \ + return /* apr_get_os_error() */; \ + } \ + ELSE_WIN_OS_IS_ANSI \ + { \ + HANDLE temp, hproc = GetCurrentProcess(); \ + if (!DuplicateHandle(hproc, name->filehand, \ + hproc, &temp, 0, TRUE, \ + DUPLICATE_SAME_ACCESS)) \ + return /* apr_get_os_error() */; \ + CloseHandle(name->filehand); \ + name->filehand = temp; \ + } \ + return /* APR_SUCCESS */; \ } \ /* Deprecated */ \ APR_DECLARE(void) apr_##name##_set_inherit(apr_##name##_t *name) \ { \ - apr_##name##_inherit_set(name); \ + /* return */ apr_##name##_inherit_set(name); \ } #define APR_IMPLEMENT_INHERIT_UNSET(name, flag, pool, cleanup) \ APR_DECLARE(void) apr_##name##_inherit_unset(apr_##name##_t *name) \ { \ - return; \ + IF_WIN_OS_IS_UNICODE \ + { \ + if (!SetHandleInformation(name->filehand, \ + HANDLE_FLAG_INHERIT, 0)) \ + return /* apr_get_os_error() */; \ + } \ + ELSE_WIN_OS_IS_ANSI \ + { \ + HANDLE temp, hproc = GetCurrentProcess(); \ + if (!DuplicateHandle(hproc, name->filehand, \ + hproc, &temp, 0, FALSE, \ + DUPLICATE_SAME_ACCESS)) \ + return /* apr_get_os_error() */; \ + CloseHandle(name->filehand); \ + name->filehand = temp; \ + } \ + return /* APR_SUCCESS */; \ } \ /* Deprecated */ \ APR_DECLARE(void) apr_##name##_unset_inherit(apr_##name##_t *name) \ { \ - apr_##name##_inherit_unset(name); \ + /* return */ apr_##name##_inherit_unset(name); \ } #endif /* ! INHERIT_H */ diff --git a/network_io/win32/sockets.c b/network_io/win32/sockets.c index 32817f2f218..af0fc80355e 100644 --- a/network_io/win32/sockets.c +++ b/network_io/win32/sockets.c @@ -424,6 +424,28 @@ APR_DECLARE(apr_status_t) apr_os_sock_put(apr_socket_t **sock, return APR_SUCCESS; } -APR_IMPLEMENT_INHERIT_SET(socket, inherit, cntxt, socket_cleanup) -APR_IMPLEMENT_INHERIT_UNSET(socket, inherit, cntxt, socket_cleanup) +/* Sockets cannot be inherited through the standard sockets + * inheritence. WSADuplicateSocket must be used. + * This is not trivial to implement. + */ + +APR_DECLARE(void) apr_socket_inherit_set(apr_socket_t *socket) +{ + return /* APR_ENOTIMPL */; +} +/* Deprecated */ +APR_DECLARE(void) apr_socket_set_inherit(apr_socket_t *socket) +{ + /* return */ apr_socket_inherit_set(socket); +} + +APR_DECLARE(void) apr_socket_inherit_unset(apr_socket_t *socket) +{ + return /* APR_ENOTIMPL */; +} +/* Deprecated */ +APR_DECLARE(void) apr_socket_unset_inherit(apr_socket_t *socket) +{ + /* return */ apr_socket_inherit_unset(socket); +}