Skip to content

Commit 55fcb2e

Browse files
committed
Once SSLMutex allowed for the setting of both the
locking method and the lockfile location, I never liked how AcceptMutex was linked to LockFile. This seemed unnecessary. Much better to have AcceptMutex do both as well. Plus, now that we will likely see other modules require a "standard" way of setting mutexes, why not have Apache provide that as an API of sorts. Anyway, LockFile is now depreciated and AcceptMutex is now SSLMutex-like. We also provide a short function that "parses" out a mutex parameter and strips out the mechanism and lockfile location. AcceptMutex and SSLMutex is this capability. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@467326 13f79535-47bb-0310-9956-ffa450edef68
1 parent 3f91379 commit 55fcb2e

12 files changed

Lines changed: 307 additions & 161 deletions

File tree

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changes with Apache 2.3.0
33
[Remove entries to the current 2.0 and 2.2 section below, when backported]
44

5+
*) The LockFile directive, which specifies the location of
6+
the accept() mutex lockfile, is depreciated. Instead, the
7+
AcceptMutex directive now takes an optional lockfile
8+
location parameter, ala SSLMutex. [Jim Jagielski]
9+
510
*) Fix address-in-use startup failure caused by corruption of the list of
611
listen sockets in some configurations with multiple generic Listen
712
directives. [Jeff Trawick]

docs/manual/mod/mpm_common.xml

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ accepting requests on network sockets</description>
4040

4141
<usage>
4242
<p>The <directive>AcceptMutex</directive> directives sets the
43-
method that Apache uses to serialize multiple children accepting
43+
method (and lockfile location if appropriate) that Apache uses to
44+
serialize multiple children accepting
4445
requests on network sockets. Prior to Apache 2.0, the method was
4546
selectable only at compile time. The optimal method to use is
4647
highly architecture and platform dependent. For further details,
@@ -55,25 +56,42 @@ accepting requests on network sockets</description>
5556
listing the available methods.</p>
5657

5758
<dl>
58-
<dt><code>flock</code></dt>
59+
<dt><code>flock&lt;<i>:/path/to/lockfile</i>&gt;</code></dt>
5960
<dd>uses the <code>flock(2)</code> system call to lock the
60-
file defined by the <directive module="mpm_common"
61-
>LockFile</directive> directive.</dd>
61+
file defined by the optional <i>/path/to/lockfile</i>
62+
parameter. One can also use the <directive module="mpm_common"
63+
>LockFile</directive> directive to specify the lockfile,
64+
although this is depreciated.</dd>
6265

63-
<dt><code>fcntl</code></dt>
66+
<dt><code>fcntl&lt;<i>:/path/to/lockfile</i>&gt;</code></dt>
6467
<dd>uses the <code>fcntl(2)</code> system call to lock the
65-
file defined by the <directive module="mpm_common"
66-
>LockFile</directive> directive.</dd>
68+
file defined by the optional <i>/path/to/lockfile</i>
69+
parameter. One can also use the <directive module="mpm_common"
70+
>LockFile</directive> directive to specify the lockfile,
71+
although this is depreciated.</dd>
72+
73+
<dt><code>file&lt;<i>:/path/to/lockfile</i>&gt;</code></dt>
74+
<dd>This directive tells the SSL Module to pick the "best" file locking
75+
implementation available to it, choosing between <code>fcntl</code> and
76+
<code>flock</code>, in that order. It is only available when the underlying
77+
platform and <glossary>APR</glossary> supports at least one of the 2.</dd>
6778

6879
<dt><code>posixsem</code></dt>
6980
<dd>uses POSIX compatible semaphores to implement the mutex.</dd>
7081

82+
<dt><code>sysvsem</code></dt>
83+
<dd>uses SySV-style semaphores to implement the mutex.</dd>
84+
85+
<dt><code>sem</code></dt>
86+
<dd>This directive tells the SSL Module to pick the "best" semaphore
87+
implementation available to it, choosing between Posix and SystemV IPC,
88+
in that order. It is only available when the underlying platform and
89+
<glossary>APR</glossary> supports at least one of the 2.</dd>
90+
7191
<dt><code>pthread</code></dt>
7292
<dd>uses POSIX mutexes as implemented by the POSIX Threads
7393
(PThreads) specification.</dd>
7494

75-
<dt><code>sysvsem</code></dt>
76-
<dd>uses SySV-style semaphores to implement the mutex.</dd>
7795
</dl>
7896

7997
<p>If you want to find out the compile time chosen default
@@ -386,7 +404,7 @@ The <var>protocol</var> argument was added in 2.1.5</compatibility>
386404

387405
<directivesynopsis>
388406
<name>LockFile</name>
389-
<description>Location of the accept serialization lock file</description>
407+
<description>Location of the accept serialization lock file <b>(depreciated)</b></description>
390408
<syntax>LockFile <var>filename</var></syntax>
391409
<default>LockFile logs/accept.lock</default>
392410
<contextlist><context>server config</context></contextlist>
@@ -412,6 +430,13 @@ The <var>protocol</var> argument was added in 2.1.5</compatibility>
412430
creating a lockfile with the same name as the one the server will try
413431
to create.</p>
414432
</note>
433+
<note type="warning"><title>Depreciated</title>
434+
<p>This directive is depreciated. It is strongly suggested that
435+
you use <directive module="mpm_common">AcceptMutex</directive> to
436+
specify both the mutex locking implementation as well as
437+
the lockfile location.</p>
438+
</note>
439+
415440
</usage>
416441
<seealso><directive module="mpm_common">AcceptMutex</directive></seealso>
417442
</directivesynopsis>

include/ap_mmn.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@
124124
* 20060905.0 (2.3.0-dev) Replaced ap_get_server_version() with
125125
* ap_get_server_banner() and ap_get_server_description()
126126
* 20060905.1 (2.3.0-dev) Enable retry=0 for the worker (minor)
127+
* 20060905.2 (2.3.0-dev) Added ap_all_available_mutexes_string,
128+
* ap_available_mutexes_string and
129+
* ap_parse_mutex()
127130
*
128131
*/
129132

include/mpm_common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ const char *ap_mpm_set_lockfile(cmd_parms *cmd, void *dummy,
286286
*/
287287
#ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
288288
extern apr_lockmech_e ap_accept_lock_mech;
289-
extern const char ap_valid_accept_mutex_string[];
290289
const char *ap_mpm_set_accept_lock_mech(cmd_parms *cmd, void *dummy,
291290
const char *arg);
292291
#endif

include/util_mutex.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
* @file util_mutex.h
19+
* @brief Apache Mutex support library
20+
*
21+
* @defgroup APACHE_CORE_MUTEX Mutex Library
22+
* @ingroup APACHE_CORE
23+
* @{
24+
*/
25+
26+
#ifndef UTIL_MUTEX_H
27+
#define UTIL_MUTEX_H
28+
29+
#include "httpd.h"
30+
#include "apr_global_mutex.h"
31+
32+
#ifdef __cplusplus
33+
extern "C" {
34+
#endif
35+
36+
AP_DECLARE_DATA extern const char ap_available_mutexes_string[];
37+
AP_DECLARE_DATA extern const char ap_all_available_mutexes_string[];
38+
39+
/**
40+
* Get Mutex config data and parse it
41+
* @param arg The mutex config string
42+
* @param pool The allocation pool
43+
* @param mutexmech The APR mutex locking mechanism
44+
* @param mutexfile The lockfile to use as required
45+
* @return APR status code
46+
* @deffunc apr_status_t ap_parse_mutex(const char *arg, apr_pool_t *pool,
47+
apr_lockmech_e *mutexmech,
48+
const char **mutexfile)
49+
*/
50+
AP_DECLARE(apr_status_t) ap_parse_mutex(const char *arg, apr_pool_t *pool,
51+
apr_lockmech_e *mutexmech,
52+
const char **mutexfile);
53+
54+
55+
#ifdef __cplusplus
56+
}
57+
#endif
58+
59+
#endif /* UTIL_MUTEX_H */
60+
/** @} */

modules/ssl/mod_ssl.c

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "ssl_private.h"
2828
#include "mod_ssl.h"
2929
#include "util_md5.h"
30+
#include "util_mutex.h"
3031
#include <assert.h>
3132

3233
/*
@@ -47,36 +48,11 @@
4748

4849
#define AP_END_CMD { NULL }
4950

50-
const char ssl_valid_ssl_mutex_string[] =
51-
"Valid SSLMutex mechanisms are: `none', `default'"
52-
#if APR_HAS_FLOCK_SERIALIZE
53-
", `flock:/path/to/file'"
54-
#endif
55-
#if APR_HAS_FCNTL_SERIALIZE
56-
", `fcntl:/path/to/file'"
57-
#endif
58-
#if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)
59-
", `sysvsem'"
60-
#endif
61-
#if APR_HAS_POSIXSEM_SERIALIZE
62-
", `posixsem'"
63-
#endif
64-
#if APR_HAS_PROC_PTHREAD_SERIALIZE
65-
", `pthread'"
66-
#endif
67-
#if APR_HAS_FLOCK_SERIALIZE || APR_HAS_FCNTL_SERIALIZE
68-
", `file:/path/to/file'"
69-
#endif
70-
#if (APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)) || APR_HAS_POSIXSEM_SERIALIZE
71-
", `sem'"
72-
#endif
73-
" ";
74-
7551
static const command_rec ssl_config_cmds[] = {
7652
/*
7753
* Global (main-server) context configuration directives
7854
*/
79-
SSL_CMD_SRV(Mutex, TAKE1, ssl_valid_ssl_mutex_string)
55+
SSL_CMD_SRV(Mutex, TAKE1, ap_all_available_mutexes_string)
8056
SSL_CMD_SRV(PassPhraseDialog, TAKE1,
8157
"SSL dialog mechanism for the pass phrase query "
8258
"(`builtin', `|/path/to/pipe_program`, "

modules/ssl/ssl_engine_config.c

Lines changed: 13 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
damned if you don't.''
2828
-- Unknown */
2929
#include "ssl_private.h"
30+
#include "util_mutex.h"
3031

3132
/* _________________________________________________________________
3233
**
@@ -337,17 +338,9 @@ const char *ssl_cmd_SSLMutex(cmd_parms *cmd,
337338
void *dcfg,
338339
const char *arg_)
339340
{
341+
apr_status_t rv;
340342
const char *err;
341343
SSLModConfigRec *mc = myModConfig(cmd->server);
342-
/* Split arg_ into meth and file */
343-
char *meth = apr_pstrdup(cmd->temp_pool, arg_);
344-
char *file = strchr(meth, ':');
345-
if (file) {
346-
*(file++) = '\0';
347-
if (!*file) {
348-
file = NULL;
349-
}
350-
}
351344

352345
if ((err = ap_check_cmd_context(cmd, GLOBAL_ONLY))) {
353346
return err;
@@ -356,72 +349,22 @@ const char *ssl_cmd_SSLMutex(cmd_parms *cmd,
356349
if (ssl_config_global_isfixed(mc)) {
357350
return NULL;
358351
}
359-
if (!strcasecmp(meth, "none") || !strcasecmp(meth, "no")) {
360-
mc->nMutexMode = SSL_MUTEXMODE_NONE;
361-
return NULL;
362-
}
363352

364-
/* APR determines temporary filename unless overridden below,
365-
* we presume file indicates an szMutexFile is a file path
366-
* unless the method sets szMutexFile=file and NULLs file
367-
*/
368-
mc->nMutexMode = SSL_MUTEXMODE_USED;
369-
mc->szMutexFile = NULL;
353+
rv = ap_parse_mutex(arg_, cmd->server->process->pool,
354+
&mc->nMutexMech, &mc->szMutexFile);
370355

371-
/* NOTE: previously, 'yes' implied 'sem' */
372-
if (!strcasecmp(meth, "default") || !strcasecmp(meth, "yes")) {
373-
mc->nMutexMech = APR_LOCK_DEFAULT;
374-
}
375-
#if APR_HAS_FCNTL_SERIALIZE
376-
else if ((!strcasecmp(meth, "fcntl") || !strcasecmp(meth, "file")) && file) {
377-
mc->nMutexMech = APR_LOCK_FCNTL;
378-
}
379-
#endif
380-
#if APR_HAS_FLOCK_SERIALIZE
381-
else if ((!strcasecmp(meth, "flock") || !strcasecmp(meth, "file")) && file) {
382-
mc->nMutexMech = APR_LOCK_FLOCK;
383-
}
384-
#endif
385-
#if APR_HAS_POSIXSEM_SERIALIZE
386-
else if (!strcasecmp(meth, "posixsem") || !strcasecmp(meth, "sem")) {
387-
mc->nMutexMech = APR_LOCK_POSIXSEM;
388-
/* Posix/SysV semaphores aren't file based, use the literal name
389-
* if provided and fall back on APR's default if not. Today, APR
390-
* will ignore it, but once supported it has an absurdly short limit.
391-
*/
392-
if (file) {
393-
mc->szMutexFile = apr_pstrdup(cmd->server->process->pool, file);
394-
395-
file = NULL;
396-
}
397-
}
398-
#endif
399-
#if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)
400-
else if (!strcasecmp(meth, "sysvsem") || !strcasecmp(meth, "sem")) {
401-
mc->nMutexMech = APR_LOCK_SYSVSEM;
402-
}
403-
#endif
404-
#if APR_HAS_PROC_PTHREAD_SERIALIZE
405-
else if (!strcasecmp(meth, "pthread")) {
406-
mc->nMutexMech = APR_LOCK_PROC_PTHREAD;
407-
}
408-
#endif
409-
else {
356+
if (rv == APR_ENOLOCK) {
357+
mc->nMutexMode = SSL_MUTEXMODE_NONE;
358+
return NULL;
359+
} else if (rv == APR_ENOTIMPL) {
410360
return apr_pstrcat(cmd->pool, "Invalid SSLMutex argument ", arg_,
411-
" (", ssl_valid_ssl_mutex_string, ")", NULL);
361+
" (", ap_all_available_mutexes_string, ")", NULL);
362+
} else if (rv == APR_BADARG) {
363+
return apr_pstrcat(cmd->pool, "Invalid SSLMutex filepath ",
364+
arg_, NULL);
412365
}
413366

414-
/* Unless the method above assumed responsibility for setting up
415-
* mc->szMutexFile and NULLing out file, presume it is a file we
416-
* are looking to use
417-
*/
418-
if (file) {
419-
mc->szMutexFile = ap_server_root_relative(cmd->server->process->pool, file);
420-
if (!mc->szMutexFile) {
421-
return apr_pstrcat(cmd->pool, "Invalid SSLMutex ", meth,
422-
": filepath ", file, NULL);
423-
}
424-
}
367+
mc->nMutexMode = SSL_MUTEXMODE_USED;
425368

426369
return NULL;
427370
}

modules/ssl/ssl_private.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,6 @@ typedef struct {
491491
/** API glue structures */
492492
extern module AP_MODULE_DECLARE_DATA ssl_module;
493493

494-
/** "global" stuff */
495-
extern const char ssl_valid_ssl_mutex_string[];
496-
497494
/** configuration handling */
498495
SSLModConfigRec *ssl_config_global_create(server_rec *);
499496
void ssl_config_global_fix(SSLModConfigRec *);

server/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LTLIBRARY_SOURCES = \
1010
test_char.h \
1111
config.c log.c main.c vhost.c util.c \
1212
util_script.c util_md5.c util_cfgtree.c util_ebcdic.c util_time.c \
13-
connection.c listen.c \
13+
connection.c listen.c util_mutex.c \
1414
mpm_common.c util_charset.c util_debug.c util_xml.c \
1515
util_filter.c util_pcre.c exports.c \
1616
scoreboard.c error_bucket.c protocol.c core.c request.c provider.c \

server/core.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "apr_buckets.h"
4343
#include "util_filter.h"
4444
#include "util_ebcdic.h"
45+
#include "util_mutex.h"
4546
#include "mpm.h"
4647
#include "mpm_common.h"
4748
#include "scoreboard.h"
@@ -3322,7 +3323,7 @@ AP_INIT_TAKE1("ScoreBoardFile", ap_mpm_set_scoreboard, NULL, RSRC_CONF,
33223323
#endif
33233324
#ifdef AP_MPM_WANT_SET_LOCKFILE
33243325
AP_INIT_TAKE1("LockFile", ap_mpm_set_lockfile, NULL, RSRC_CONF,
3325-
"The lockfile used when Apache needs to lock the accept() call"),
3326+
"The lockfile used when Apache needs to lock the accept() call (depreciated)"),
33263327
#endif
33273328
#ifdef AP_MPM_WANT_SET_MAX_REQUESTS
33283329
AP_INIT_TAKE1("MaxRequestsPerChild", ap_mpm_set_max_requests, NULL, RSRC_CONF,
@@ -3334,7 +3335,7 @@ AP_INIT_TAKE1("CoreDumpDirectory", ap_mpm_set_coredumpdir, NULL, RSRC_CONF,
33343335
#endif
33353336
#ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
33363337
AP_INIT_TAKE1("AcceptMutex", ap_mpm_set_accept_lock_mech, NULL, RSRC_CONF,
3337-
ap_valid_accept_mutex_string),
3338+
ap_available_mutexes_string),
33383339
#endif
33393340
#ifdef AP_MPM_WANT_SET_MAX_MEM_FREE
33403341
AP_INIT_TAKE1("MaxMemFree", ap_mpm_set_max_mem_free, NULL, RSRC_CONF,

0 commit comments

Comments
 (0)