bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / modules / ssl / ssl_engine_mutex.c
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /*                      _             _
18  *  _ __ ___   ___   __| |    ___ ___| |  mod_ssl
19  * | '_ ` _ \ / _ \ / _` |   / __/ __| |  Apache Interface to OpenSSL
20  * | | | | | | (_) | (_| |   \__ \__ \ |
21  * |_| |_| |_|\___/ \__,_|___|___/___/_|
22  *                      |_____|
23  *  ssl_engine_mutex.c
24  *  Semaphore for Mutual Exclusion
25  */
26                              /* ``Real programmers confuse
27                                   Christmas and Halloween
28                                   because DEC 25 = OCT 31.''
29                                              -- Unknown     */
30
31 #include "mod_ssl.h"
32 #if !defined(OS2) && !defined(WIN32) && !defined(BEOS) && !defined(NETWARE)
33 #include "unixd.h"
34 #define MOD_SSL_SET_MUTEX_PERMS /* XXX Apache should define something */
35 #endif
36
37 int ssl_mutex_init(server_rec *s, apr_pool_t *p)
38 {
39     SSLModConfigRec *mc = myModConfig(s);
40     apr_status_t rv;
41
42     if (mc->nMutexMode == SSL_MUTEXMODE_NONE) 
43         return TRUE;
44
45     if ((rv = apr_global_mutex_create(&mc->pMutex, mc->szMutexFile,
46                                 mc->nMutexMech, p)) != APR_SUCCESS) {
47         if (mc->szMutexFile)
48             ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
49                          "Cannot create SSLMutex with file `%s'",
50                          mc->szMutexFile);
51         else
52             ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
53                          "Cannot create SSLMutex");
54         return FALSE;
55     }
56
57 #ifdef MOD_SSL_SET_MUTEX_PERMS
58     rv = unixd_set_global_mutex_perms(mc->pMutex);
59     if (rv != APR_SUCCESS) {
60         ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
61                      "Could not set permissions on ssl_mutex; check User "
62                      "and Group directives");
63         return FALSE;
64     }
65 #endif
66     return TRUE;
67 }
68
69 int ssl_mutex_reinit(server_rec *s, apr_pool_t *p)
70 {
71     SSLModConfigRec *mc = myModConfig(s);
72     apr_status_t rv;
73
74     if (mc->nMutexMode == SSL_MUTEXMODE_NONE)
75         return TRUE;
76
77     if ((rv = apr_global_mutex_child_init(&mc->pMutex,
78                                     mc->szMutexFile, p)) != APR_SUCCESS) {
79         if (mc->szMutexFile)
80             ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
81                          "Cannot reinit SSLMutex with file `%s'",
82                          mc->szMutexFile);
83         else
84             ap_log_error(APLOG_MARK, APLOG_WARNING, rv, s,
85                          "Cannot reinit SSLMutex");
86         return FALSE;
87     }
88     return TRUE;
89 }
90
91 int ssl_mutex_on(server_rec *s)
92 {
93     SSLModConfigRec *mc = myModConfig(s);
94     apr_status_t rv;
95
96     if (mc->nMutexMode == SSL_MUTEXMODE_NONE)
97         return TRUE;
98     if ((rv = apr_global_mutex_lock(mc->pMutex)) != APR_SUCCESS) {
99         ap_log_error(APLOG_MARK, APLOG_WARNING, rv, s,
100                      "Failed to acquire global mutex lock");
101         return FALSE;
102     }
103     return TRUE;
104 }
105
106 int ssl_mutex_off(server_rec *s)
107 {
108     SSLModConfigRec *mc = myModConfig(s);
109     apr_status_t rv;
110
111     if (mc->nMutexMode == SSL_MUTEXMODE_NONE)
112         return TRUE;
113     if ((rv = apr_global_mutex_unlock(mc->pMutex)) != APR_SUCCESS) {
114         ap_log_error(APLOG_MARK, APLOG_WARNING, rv, s,
115                      "Failed to release global mutex lock");
116         return FALSE;
117     }
118     return TRUE;
119 }
120