1 /* Copyright 2001-2004 The Apache Software Foundation
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 * _ __ ___ ___ __| | ___ ___| | mod_ssl
18 * | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
19 * | | | | | | (_) | (_| | \__ \__ \ |
20 * |_| |_| |_|\___/ \__,_|___|___/___/_|
23 * Semaphore for Mutual Exclusion
25 /* ``Real programmers confuse
26 Christmas and Halloween
27 because DEC 25 = OCT 31.''
30 #include "ssl_private.h"
31 #if !defined(OS2) && !defined(WIN32) && !defined(BEOS) && !defined(NETWARE)
33 #define MOD_SSL_SET_MUTEX_PERMS /* XXX Apache should define something */
36 int ssl_mutex_init(server_rec *s, apr_pool_t *p)
38 SSLModConfigRec *mc = myModConfig(s);
41 if (mc->nMutexMode == SSL_MUTEXMODE_NONE)
47 if ((rv = apr_global_mutex_create(&mc->pMutex, mc->szMutexFile,
48 mc->nMutexMech, s->process->pool))
51 ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
52 "Cannot create SSLMutex with file `%s'",
55 ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
56 "Cannot create SSLMutex");
60 #ifdef MOD_SSL_SET_MUTEX_PERMS
61 rv = unixd_set_global_mutex_perms(mc->pMutex);
62 if (rv != APR_SUCCESS) {
63 ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
64 "Could not set permissions on ssl_mutex; check User "
65 "and Group directives");
72 int ssl_mutex_reinit(server_rec *s, apr_pool_t *p)
74 SSLModConfigRec *mc = myModConfig(s);
77 if (mc->nMutexMode == SSL_MUTEXMODE_NONE)
80 if ((rv = apr_global_mutex_child_init(&mc->pMutex,
81 mc->szMutexFile, p)) != APR_SUCCESS) {
83 ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
84 "Cannot reinit SSLMutex with file `%s'",
87 ap_log_error(APLOG_MARK, APLOG_WARNING, rv, s,
88 "Cannot reinit SSLMutex");
94 int ssl_mutex_on(server_rec *s)
96 SSLModConfigRec *mc = myModConfig(s);
99 if (mc->nMutexMode == SSL_MUTEXMODE_NONE)
101 if ((rv = apr_global_mutex_lock(mc->pMutex)) != APR_SUCCESS) {
102 ap_log_error(APLOG_MARK, APLOG_WARNING, rv, s,
103 "Failed to acquire global mutex lock");
109 int ssl_mutex_off(server_rec *s)
111 SSLModConfigRec *mc = myModConfig(s);
114 if (mc->nMutexMode == SSL_MUTEXMODE_NONE)
116 if ((rv = apr_global_mutex_unlock(mc->pMutex)) != APR_SUCCESS) {
117 ap_log_error(APLOG_MARK, APLOG_WARNING, rv, s,
118 "Failed to release global mutex lock");