diff options
author | Jim Jagielski <jim@apache.org> | 2006-10-24 13:17:29 +0000 |
---|---|---|
committer | Jim Jagielski <jim@apache.org> | 2006-10-24 13:17:29 +0000 |
commit | 707d1dabb908ca954b4a5a11aa6f998d76b07499 (patch) | |
tree | 72c7d65b98991a8e825caa45862150d7adb49f3d /server | |
parent | ae0b0e4d651bc8f8ff397ce24510bd1605225606 (diff) | |
download | httpd-707d1dabb908ca954b4a5a11aa6f998d76b07499.tar.gz |
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
Diffstat (limited to 'server')
-rw-r--r-- | server/Makefile.in | 2 | ||||
-rw-r--r-- | server/core.c | 5 | ||||
-rw-r--r-- | server/mpm_common.c | 66 | ||||
-rw-r--r-- | server/util_mutex.c | 167 |
4 files changed, 189 insertions, 51 deletions
diff --git a/server/Makefile.in b/server/Makefile.in index bd4f8fc79a..0a64441aba 100644 --- a/server/Makefile.in +++ b/server/Makefile.in @@ -10,7 +10,7 @@ LTLIBRARY_SOURCES = \ test_char.h \ config.c log.c main.c vhost.c util.c \ util_script.c util_md5.c util_cfgtree.c util_ebcdic.c util_time.c \ - connection.c listen.c \ + connection.c listen.c util_mutex.c \ mpm_common.c util_charset.c util_debug.c util_xml.c \ util_filter.c util_pcre.c exports.c \ scoreboard.c error_bucket.c protocol.c core.c request.c provider.c \ diff --git a/server/core.c b/server/core.c index 24e14a4248..5f7d3241cd 100644 --- a/server/core.c +++ b/server/core.c @@ -42,6 +42,7 @@ #include "apr_buckets.h" #include "util_filter.h" #include "util_ebcdic.h" +#include "util_mutex.h" #include "mpm.h" #include "mpm_common.h" #include "scoreboard.h" @@ -3322,7 +3323,7 @@ AP_INIT_TAKE1("ScoreBoardFile", ap_mpm_set_scoreboard, NULL, RSRC_CONF, #endif #ifdef AP_MPM_WANT_SET_LOCKFILE AP_INIT_TAKE1("LockFile", ap_mpm_set_lockfile, NULL, RSRC_CONF, - "The lockfile used when Apache needs to lock the accept() call"), + "The lockfile used when Apache needs to lock the accept() call (depreciated)"), #endif #ifdef AP_MPM_WANT_SET_MAX_REQUESTS 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, #endif #ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH AP_INIT_TAKE1("AcceptMutex", ap_mpm_set_accept_lock_mech, NULL, RSRC_CONF, - ap_valid_accept_mutex_string), + ap_available_mutexes_string), #endif #ifdef AP_MPM_WANT_SET_MAX_MEM_FREE AP_INIT_TAKE1("MaxMemFree", ap_mpm_set_max_mem_free, NULL, RSRC_CONF, diff --git a/server/mpm_common.c b/server/mpm_common.c index 26a7489103..ac85bb087b 100644 --- a/server/mpm_common.c +++ b/server/mpm_common.c @@ -44,6 +44,7 @@ #include "ap_mpm.h" #include "ap_listen.h" #include "mpm_default.h" +#include "util_mutex.h" #ifdef AP_MPM_WANT_SET_SCOREBOARD #include "scoreboard.h" @@ -810,72 +811,41 @@ const char * ap_mpm_set_graceful_shutdown(cmd_parms *cmd, void *dummy, #ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH apr_lockmech_e ap_accept_lock_mech = APR_LOCK_DEFAULT; -const char ap_valid_accept_mutex_string[] = - "Valid accept mutexes for this platform and MPM are: default" -#if APR_HAS_FLOCK_SERIALIZE - ", flock" -#endif -#if APR_HAS_FCNTL_SERIALIZE - ", fcntl" -#endif -#if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM) - ", sysvsem" -#endif -#if APR_HAS_POSIXSEM_SERIALIZE - ", posixsem" -#endif -#if APR_HAS_PROC_PTHREAD_SERIALIZE - ", pthread" -#endif - "."; - AP_DECLARE(const char *) ap_mpm_set_accept_lock_mech(cmd_parms *cmd, void *dummy, const char *arg) { + apr_status_t rv; + const char *lockfile; const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); if (err != NULL) { return err; } - if (!strcasecmp(arg, "default")) { - ap_accept_lock_mech = APR_LOCK_DEFAULT; - } -#if APR_HAS_FLOCK_SERIALIZE - else if (!strcasecmp(arg, "flock")) { - ap_accept_lock_mech = APR_LOCK_FLOCK; - } -#endif -#if APR_HAS_FCNTL_SERIALIZE - else if (!strcasecmp(arg, "fcntl")) { - ap_accept_lock_mech = APR_LOCK_FCNTL; + rv = ap_parse_mutex(arg, cmd->server->process->pool, + &ap_accept_lock_mech, &lockfile); + + if ((rv == APR_ENOTIMPL) || (rv == APR_ENOLOCK)) { + return apr_pstrcat(cmd->pool, "Invalid AcceptMutex argument ", arg, + " (", ap_available_mutexes_string, ")", NULL); + } else if (rv == APR_BADARG) { + return apr_pstrcat(cmd->pool, "Invalid AcceptMutex filepath ", + arg, NULL); } -#endif /* perchild can't use SysV sems because the permissions on the accept * mutex can't be set to allow all processes to use the mutex and * at the same time keep all users from being able to dink with the * mutex */ -#if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM) - else if (!strcasecmp(arg, "sysvsem")) { - ap_accept_lock_mech = APR_LOCK_SYSVSEM; - } -#endif -#if APR_HAS_POSIXSEM_SERIALIZE - else if (!strcasecmp(arg, "posixsem")) { - ap_accept_lock_mech = APR_LOCK_POSIXSEM; +#if defined(PERCHILD_MPM) + if (ap_accept_lock_mech == APR_LOCK_SYSVSEM) { + return apr_pstrcat(cmd->pool, "Invalid AcceptMutex argument ", arg, + " (", ap_available_mutexes_string, ")", NULL); } #endif -#if APR_HAS_PROC_PTHREAD_SERIALIZE - else if (!strcasecmp(arg, "pthread")) { - ap_accept_lock_mech = APR_LOCK_PROC_PTHREAD; - } -#endif - else { - return apr_pstrcat(cmd->pool, arg, " is an invalid mutex mechanism; ", - ap_valid_accept_mutex_string, NULL); - } + if (lockfile && !ap_lock_fname) + ap_lock_fname = lockfile; return NULL; } diff --git a/server/util_mutex.c b/server/util_mutex.c new file mode 100644 index 0000000000..c8017b6ddc --- /dev/null +++ b/server/util_mutex.c @@ -0,0 +1,167 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * util_mutex.c: Useful functions for determining allowable + * mutexes and mutex settings + */ + + +#include "apr.h" +#include "apr_strings.h" +#include "apr_lib.h" + +#define APR_WANT_STRFUNC +#include "apr_want.h" + +#define CORE_PRIVATE + +#include "ap_config.h" +#include "httpd.h" +#include "http_main.h" +#include "http_config.h" +#include "util_mutex.h" + +AP_DECLARE_DATA const char ap_all_available_mutexes_string[] = + "Mutex mechanisms are: `none', `default'" +#if APR_HAS_FLOCK_SERIALIZE + ", `flock:/path/to/file'" +#endif +#if APR_HAS_FCNTL_SERIALIZE + ", `fcntl:/path/to/file'" +#endif +#if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM) + ", `sysvsem'" +#endif +#if APR_HAS_POSIXSEM_SERIALIZE + ", `posixsem'" +#endif +#if APR_HAS_PROC_PTHREAD_SERIALIZE + ", `pthread'" +#endif +#if APR_HAS_FLOCK_SERIALIZE || APR_HAS_FCNTL_SERIALIZE + ", `file:/path/to/file'" +#endif +#if (APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)) || APR_HAS_POSIXSEM_SERIALIZE + ", `sem'" +#endif + " "; + +AP_DECLARE_DATA const char ap_available_mutexes_string[] = + "Mutex mechanisms are: `default'" +#if APR_HAS_FLOCK_SERIALIZE + ", `flock:/path/to/file'" +#endif +#if APR_HAS_FCNTL_SERIALIZE + ", `fcntl:/path/to/file'" +#endif +#if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM) + ", `sysvsem'" +#endif +#if APR_HAS_POSIXSEM_SERIALIZE + ", `posixsem'" +#endif +#if APR_HAS_PROC_PTHREAD_SERIALIZE + ", `pthread'" +#endif +#if APR_HAS_FLOCK_SERIALIZE || APR_HAS_FCNTL_SERIALIZE + ", `file:/path/to/file'" +#endif +#if (APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)) || APR_HAS_POSIXSEM_SERIALIZE + ", `sem'" +#endif + " "; + + +AP_DECLARE(apr_status_t) ap_parse_mutex(const char *arg, apr_pool_t *pool, + apr_lockmech_e *mutexmech, + const char **mutexfile) +{ + /* Split arg into meth and file */ + char *meth = apr_pstrdup(pool, arg); + char *file = strchr(meth, ':'); + if (file) { + *(file++) = '\0'; + if (!*file) { + file = NULL; + } + } + + if (!strcasecmp(meth, "none") || !strcasecmp(meth, "no")) { + return APR_ENOLOCK; + } + + /* APR determines temporary filename unless overridden below, + * we presume file indicates an mutexfile is a file path + * unless the method sets mutexfile=file and NULLs file + */ + *mutexfile = NULL; + + /* NOTE: previously, 'yes' implied 'sem' */ + if (!strcasecmp(meth, "default") || !strcasecmp(meth, "yes")) { + *mutexmech = APR_LOCK_DEFAULT; + } +#if APR_HAS_FCNTL_SERIALIZE + else if (!strcasecmp(meth, "fcntl") || !strcasecmp(meth, "file")) { + *mutexmech = APR_LOCK_FCNTL; + } +#endif +#if APR_HAS_FLOCK_SERIALIZE + else if (!strcasecmp(meth, "flock") || !strcasecmp(meth, "file")) { + *mutexmech = APR_LOCK_FLOCK; + } +#endif +#if APR_HAS_POSIXSEM_SERIALIZE + else if (!strcasecmp(meth, "posixsem") || !strcasecmp(meth, "sem")) { + *mutexmech = APR_LOCK_POSIXSEM; + /* Posix/SysV semaphores aren't file based, use the literal name + * if provided and fall back on APR's default if not. Today, APR + * will ignore it, but once supported it has an absurdly short limit. + */ + if (file) { + *mutexfile = apr_pstrdup(pool, file); + + file = NULL; + } + } +#endif +#if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM) + else if (!strcasecmp(meth, "sysvsem") || !strcasecmp(meth, "sem")) { + *mutexmech = APR_LOCK_SYSVSEM; + } +#endif +#if APR_HAS_PROC_PTHREAD_SERIALIZE + else if (!strcasecmp(meth, "pthread")) { + *mutexmech = APR_LOCK_PROC_PTHREAD; + } +#endif + else { + return APR_ENOTIMPL; + } + + /* Unless the method above assumed responsibility for setting up + * mutexfile and NULLing out file, presume it is a file we + * are looking to use + */ + if (file) { + *mutexfile = ap_server_root_relative(pool, file); + if (!*mutexfile) { + return APR_BADARG; + } + } + + return APR_SUCCESS; +} |