Apache HTTPD
framework
httpd-2.4.62
modules
ssl
ssl_engine_mutex.c
Go to the documentation of this file.
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 "
ssl_private.h
"
32
33
int
ssl_mutex_init
(
server_rec
*
s
,
apr_pool_t
*
p
)
34
{
35
SSLModConfigRec
*
mc
=
myModConfig
(
s
);
36
apr_status_t
rv;
37
38
/* A mutex is only needed if a session cache is configured, and
39
* the provider used is not internally multi-process/thread
40
* safe. */
41
if
(!
mc
->sesscache
42
|| (
mc
->sesscache->
flags
&
AP_SOCACHE_FLAG_NOTMPSAFE
) == 0) {
43
return
TRUE
;
44
}
45
46
if
(
mc
->pMutex) {
47
return
TRUE
;
48
}
49
50
if
((rv =
ap_global_mutex_create
(&
mc
->pMutex,
NULL
,
SSL_CACHE_MUTEX_TYPE
,
51
NULL
,
s
,
s
->process->pool, 0))
52
!=
APR_SUCCESS
) {
53
return
FALSE
;
54
}
55
56
return
TRUE
;
57
}
58
59
int
ssl_mutex_reinit
(
server_rec
*
s
,
apr_pool_t
*
p
)
60
{
61
SSLModConfigRec
*
mc
=
myModConfig
(
s
);
62
apr_status_t
rv;
63
const
char
*
lockfile
;
64
65
if
(
mc
->pMutex ==
NULL
|| !
mc
->sesscache
66
|| (
mc
->sesscache->
flags
&
AP_SOCACHE_FLAG_NOTMPSAFE
) == 0) {
67
return
TRUE
;
68
}
69
70
lockfile
=
apr_global_mutex_lockfile
(
mc
->pMutex);
71
if
((rv =
apr_global_mutex_child_init
(&
mc
->pMutex,
72
lockfile
,
73
p
)) !=
APR_SUCCESS
) {
74
if
(
lockfile
)
75
ap_log_error
(
APLOG_MARK
,
APLOG_ERR
, rv,
s
,
APLOGNO
(02024)
76
"Cannot reinit %s mutex with file `%s'"
,
77
SSL_CACHE_MUTEX_TYPE
,
lockfile
);
78
else
79
ap_log_error
(
APLOG_MARK
,
APLOG_WARNING
, rv,
s
,
APLOGNO
(02025)
80
"Cannot reinit %s mutex"
,
SSL_CACHE_MUTEX_TYPE
);
81
return
FALSE
;
82
}
83
return
TRUE
;
84
}
85
86
int
ssl_mutex_on
(
server_rec
*
s
)
87
{
88
SSLModConfigRec
*
mc
=
myModConfig
(
s
);
89
apr_status_t
rv;
90
91
if
((rv =
apr_global_mutex_lock
(
mc
->pMutex)) !=
APR_SUCCESS
) {
92
ap_log_error
(
APLOG_MARK
,
APLOG_WARNING
, rv,
s
,
APLOGNO
(02026)
93
"Failed to acquire SSL session cache lock"
);
94
return
FALSE
;
95
}
96
return
TRUE
;
97
}
98
99
int
ssl_mutex_off
(
server_rec
*
s
)
100
{
101
SSLModConfigRec
*
mc
=
myModConfig
(
s
);
102
apr_status_t
rv;
103
104
if
((rv =
apr_global_mutex_unlock
(
mc
->pMutex)) !=
APR_SUCCESS
) {
105
ap_log_error
(
APLOG_MARK
,
APLOG_WARNING
, rv,
s
,
APLOGNO
(02027)
106
"Failed to release SSL session cache lock"
);
107
return
FALSE
;
108
}
109
return
TRUE
;
110
}
111
TRUE
#define TRUE
Definition
abts.h:38
FALSE
#define FALSE
Definition
abts.h:35
APLOGNO
#define APLOGNO(n)
Definition
http_log.h:117
APLOG_ERR
#define APLOG_ERR
Definition
http_log.h:67
ap_log_error
#define ap_log_error
Definition
http_log.h:370
APLOG_MARK
#define APLOG_MARK
Definition
http_log.h:283
APLOG_WARNING
#define APLOG_WARNING
Definition
http_log.h:68
ap_global_mutex_create
apr_status_t ap_global_mutex_create(apr_global_mutex_t **mutex, const char **name, const char *type, const char *instance_id, server_rec *server, apr_pool_t *pool, apr_int32_t options)
Definition
util_mutex.c:407
mc
apr_memcache_t * mc
Definition
apr_memcache.h:161
AP_SOCACHE_FLAG_NOTMPSAFE
#define AP_SOCACHE_FLAG_NOTMPSAFE
Definition
ap_socache.h:46
myModConfig
#define myModConfig(srv)
Definition
ssl_private.h:364
ssl_mutex_off
int ssl_mutex_off(server_rec *s)
Definition
ssl_engine_mutex.c:99
SSL_CACHE_MUTEX_TYPE
#define SSL_CACHE_MUTEX_TYPE
Definition
ssl_private.h:1127
ssl_mutex_init
int ssl_mutex_init(server_rec *s, apr_pool_t *p)
Definition
ssl_engine_mutex.c:33
ssl_mutex_reinit
int ssl_mutex_reinit(server_rec *s, apr_pool_t *p)
Definition
ssl_engine_mutex.c:59
ssl_mutex_on
int ssl_mutex_on(server_rec *s)
Definition
ssl_engine_mutex.c:86
size
apr_size_t size
Definition
apr_allocator.h:115
APR_SUCCESS
#define APR_SUCCESS
Definition
apr_errno.h:225
apr_status_t
int apr_status_t
Definition
apr_errno.h:44
s
const char * s
Definition
apr_strings.h:95
p
apr_pool_t * p
Definition
md_event.c:32
NULL
return NULL
Definition
mod_so.c:359
ssl_private.h
Internal interfaces private to mod_ssl.
SSLModConfigRec
Definition
ssl_private.h:646
apr_memcache_t::flags
apr_uint32_t flags
Definition
apr_memcache.h:100
apr_pool_t
Definition
apr_pools.c:562
server_rec
A structure to store information for each virtual server.
Definition
httpd.h:1322
Generated by
1.9.8