diff options
author | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2003-03-27 19:51:12 +0000 |
---|---|---|
committer | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2003-03-27 19:51:12 +0000 |
commit | 3fb67f74aaf9e7c85d6e94d0f1567b5da98bf621 (patch) | |
tree | 244387b04f4ea8f9c8a099706c2c62f2659d5558 /locks | |
parent | 29b88e1c7431f57ca22fca5d5bf87de73c253993 (diff) | |
download | libapr-3fb67f74aaf9e7c85d6e94d0f1567b5da98bf621.tar.gz |
Win32 needs to do nothing if the file handle is already open in a child
process, and we are using anonymous proc_mutex or global_mutex methods,
so win32 should return APR_SUCCESS for proc_mutex_child_init.
We also introduced the kernel 'object'
folding function for shared memory
section names, so reuse that folding function here to provide reliable
Win2K/XP names (prefixed with \global\) and fold away any slashes or
backslashes from that path.
Based on issues observed by "Andre Schild" <A.Schild@aarboard.ch> with
the httpd mod_ssl implementation for Win32, with input from Andre and
JimJ.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64452 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'locks')
-rw-r--r-- | locks/win32/proc_mutex.c | 69 |
1 files changed, 51 insertions, 18 deletions
diff --git a/locks/win32/proc_mutex.c b/locks/win32/proc_mutex.c index 6c6cf26e9..37a1d0cec 100644 --- a/locks/win32/proc_mutex.c +++ b/locks/win32/proc_mutex.c @@ -57,6 +57,7 @@ #include "apr_general.h" #include "apr_strings.h" #include "apr_portable.h" +#include "apr_arch_file_io.h" #include "apr_arch_proc_mutex.h" #include "apr_arch_misc.h" @@ -64,8 +65,10 @@ static apr_status_t proc_mutex_cleanup(void *mutex_) { apr_proc_mutex_t *mutex = mutex_; - if (CloseHandle(mutex->handle) == 0) { - return apr_get_os_error(); + if (mutex->handle) { + if (CloseHandle(mutex->handle) == 0) { + return apr_get_os_error(); + } } return APR_SUCCESS; } @@ -76,21 +79,32 @@ APR_DECLARE(apr_status_t) apr_proc_mutex_create(apr_proc_mutex_t **mutex, apr_pool_t *pool) { HANDLE hMutex; + void *mutexkey; - /* With Win2000 Terminal Services, the Mutex name can have a - * "Global\" or "Local\" prefix to explicitly create the object - * in the global or session name space. Without Terminal Service - * running on Win2000, Global\ and Local\ are ignored. These - * prefixes are only valid on Win2000+ + /* res_name_from_filename turns fname into a pseduo-name + * without slashes or backslashes, and prepends the \global + * prefix on Win2K and later */ if (fname) { - if (apr_os_level >= APR_WIN_2000) - fname = apr_pstrcat(pool, "Global\\", fname, NULL); - else - fname = apr_pstrdup(pool, fname); + mutexkey = res_name_from_filename(fname, 1, pool); + } + else { + mutexkey = NULL; } - hMutex = CreateMutex(NULL, FALSE, fname); +#if APR_HAS_UNICODE_FS + IF_WIN_OS_IS_UNICODE + { + hMutex = CreateMutexW(NULL, FALSE, mutexkey); + } +#endif +#if APR_HAS_ANSI_FS + ELSE_WIN_OS_IS_ANSI + { + hMutex = CreateMutexA(NULL, FALSE, mutexkey); + } +#endif + if (!hMutex) { return apr_get_os_error(); } @@ -109,13 +123,32 @@ APR_DECLARE(apr_status_t) apr_proc_mutex_child_init(apr_proc_mutex_t **mutex, apr_pool_t *pool) { HANDLE hMutex; + void *mutexkey; - if (apr_os_level >= APR_WIN_2000) - fname = apr_pstrcat(pool, "Global\\", fname, NULL); - else - fname = apr_pstrdup(pool, fname); + if (!fname) { + /* Reinitializing unnamed mutexes is a noop in the Unix code. */ + return APR_SUCCESS; + } + + /* res_name_from_filename turns file into a pseudo-name + * without slashes or backslashes, and prepends the \global + * prefix on Win2K and later + */ + mutexkey = res_name_from_filename(fname, 1, pool); + +#if APR_HAS_UNICODE_FS + IF_WIN_OS_IS_UNICODE + { + hMutex = OpenMutexW(MUTEX_ALL_ACCESS, FALSE, mutexkey); + } +#endif +#if APR_HAS_ANSI_FS + ELSE_WIN_OS_IS_ANSI + { + hMutex = OpenMutexA(MUTEX_ALL_ACCESS, FALSE, mutexkey); + } +#endif - hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, fname); if (!hMutex) { return apr_get_os_error(); } @@ -174,7 +207,7 @@ APR_DECLARE(apr_status_t) apr_proc_mutex_destroy(apr_proc_mutex_t *mutex) APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex) { - return "win32mutex"; + return mutex->fname; } APR_DECLARE(const char *) apr_proc_mutex_defname(void) |