67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim/* Licensed to the Apache Software Foundation (ASF) under one or more
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * contributor license agreements. See the NOTICE file distributed with
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * this work for additional information regarding copyright ownership.
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * The ASF licenses this file to You under the Apache License, Version 2.0
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * (the "License"); you may not use this file except in compliance with
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * the License. You may obtain a copy of the License at
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim *
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * http://www.apache.org/licenses/LICENSE-2.0
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim *
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * Unless required by applicable law or agreed to in writing, software
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * distributed under the License is distributed on an "AS IS" BASIS,
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * See the License for the specific language governing permissions and
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * limitations under the License.
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim */
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim/*
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * util_mutex.c: Useful functions for determining allowable
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * mutexes and mutex settings
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim */
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#include "apr.h"
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick#include "apr_hash.h"
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#include "apr_strings.h"
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#include "apr_lib.h"
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#define APR_WANT_STRFUNC
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#include "apr_want.h"
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#include "ap_config.h"
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#include "httpd.h"
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#include "http_main.h"
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#include "http_config.h"
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf#include "http_core.h"
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick#include "http_log.h"
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#include "util_mutex.h"
0c32a43de97332a10a45ca4213339132dd4a3844trawick#if AP_NEED_SET_MUTEX_PERMS
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick#include "unixd.h"
0c32a43de97332a10a45ca4213339132dd4a3844trawick#endif
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick#ifdef HAVE_UNISTD_H
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick#include <unistd.h> /* getpid() */
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick#endif
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf/* we know core's module_index is 0 */
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf#undef APLOG_MODULE_INDEX
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf#define APLOG_MODULE_INDEX AP_CORE_MODULE_INDEX
36ef8f77bffe75d1aa327882be1b5bdbe2ff567asf
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jimAP_DECLARE(apr_status_t) ap_parse_mutex(const char *arg, apr_pool_t *pool,
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim apr_lockmech_e *mutexmech,
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim const char **mutexfile)
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim{
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim /* Split arg into meth and file */
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim char *meth = apr_pstrdup(pool, arg);
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim char *file = strchr(meth, ':');
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim if (file) {
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim *(file++) = '\0';
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim if (!*file) {
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim file = NULL;
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim }
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim }
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim /* APR determines temporary filename unless overridden below,
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * we presume file indicates an mutexfile is a file path
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * unless the method sets mutexfile=file and NULLs file
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim */
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim *mutexfile = NULL;
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (!strcasecmp(meth, "none") || !strcasecmp(meth, "no")) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return APR_ENOLOCK;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim /* NOTE: previously, 'yes' implied 'sem' */
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim if (!strcasecmp(meth, "default") || !strcasecmp(meth, "yes")) {
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim *mutexmech = APR_LOCK_DEFAULT;
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim }
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#if APR_HAS_FCNTL_SERIALIZE
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim else if (!strcasecmp(meth, "fcntl") || !strcasecmp(meth, "file")) {
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim *mutexmech = APR_LOCK_FCNTL;
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim }
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#endif
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#if APR_HAS_FLOCK_SERIALIZE
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim else if (!strcasecmp(meth, "flock") || !strcasecmp(meth, "file")) {
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim *mutexmech = APR_LOCK_FLOCK;
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim }
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#endif
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#if APR_HAS_POSIXSEM_SERIALIZE
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim else if (!strcasecmp(meth, "posixsem") || !strcasecmp(meth, "sem")) {
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim *mutexmech = APR_LOCK_POSIXSEM;
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim /* Posix/SysV semaphores aren't file based, use the literal name
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * if provided and fall back on APR's default if not. Today, APR
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * will ignore it, but once supported it has an absurdly short limit.
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim */
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim if (file) {
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim *mutexfile = apr_pstrdup(pool, file);
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim file = NULL;
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim }
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim }
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#endif
f8aafb8bd93472f7da5a7c158958ee09e4176c8etrawick#if APR_HAS_SYSVSEM_SERIALIZE
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim else if (!strcasecmp(meth, "sysvsem") || !strcasecmp(meth, "sem")) {
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim *mutexmech = APR_LOCK_SYSVSEM;
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim }
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#endif
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#if APR_HAS_PROC_PTHREAD_SERIALIZE
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim else if (!strcasecmp(meth, "pthread")) {
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim *mutexmech = APR_LOCK_PROC_PTHREAD;
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim }
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim#endif
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim else {
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim return APR_ENOTIMPL;
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim }
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim /* Unless the method above assumed responsibility for setting up
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * mutexfile and NULLing out file, presume it is a file we
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim * are looking to use
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim */
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim if (file) {
0fdcfd7a51bf3028b0be879c43c009c16c6d3f58trawick *mutexfile = ap_runtime_dir_relative(pool, file);
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim if (!*mutexfile) {
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim return APR_BADARG;
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim }
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim }
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim return APR_SUCCESS;
67139e2d50d1e11558d87f7042f61cb04bb0d1d2jim}
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawicktypedef struct {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick apr_int32_t options;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick int set;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick int none;
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick int omit_pid;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick apr_lockmech_e mech;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick const char *dir;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick} mutex_cfg_t;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick/* hash is created the first time a module calls ap_mutex_register(),
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick * rather than attempting to be the REALLY_REALLY_FIRST pre-config
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick * hook; it is cleaned up when the associated pool goes away; assume
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick * pconf is the pool passed to ap_mutex_register()
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick */
11f2c481e1d57bedb3f758565307501e9a2730ddtrawickstatic apr_hash_t *mxcfg_by_type;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
ead0b57bbeaec5acb14f931b5641962f429dabc9trawickAP_DECLARE_NONSTD(void) ap_mutex_init(apr_pool_t *p)
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick{
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick mutex_cfg_t *def;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (mxcfg_by_type) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick mxcfg_by_type = apr_hash_make(p);
f6e47621625cca111811e84e407be84b5b18e9c5sf apr_pool_cleanup_register(p, &mxcfg_by_type, ap_pool_cleanup_set_null,
f6e47621625cca111811e84e407be84b5b18e9c5sf apr_pool_cleanup_null);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick /* initialize default mutex configuration */
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick def = apr_pcalloc(p, sizeof *def);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick def->mech = APR_LOCK_DEFAULT;
8ba562720ad913bc899d15deba8b83dfe1065c0ejim def->dir = ap_runtime_dir_relative(p, "");
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick apr_hash_set(mxcfg_by_type, "default", APR_HASH_KEY_STRING, def);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick}
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
f4c8f0f5f11dd9f387441204fbe6d109f5c4eb25trawickAP_DECLARE_NONSTD(const char *)ap_set_mutex(cmd_parms *cmd, void *dummy,
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick const char *arg)
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick{
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick apr_pool_t *p = cmd->pool;
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick const char **elt;
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick const char *mechdir;
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick int no_mutex = 0, omit_pid = 0;
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick apr_array_header_t *type_list;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick apr_lockmech_e mech;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick apr_status_t rv;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick const char *mutexdir;
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick mutex_cfg_t *mxcfg;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (err != NULL) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return err;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick mechdir = ap_getword_conf(cmd->pool, &arg);
d88a642829b2aa45e810f5bcc31be8e901b0aa3btrawick if (*mechdir == '\0') {
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim return "Mutex requires at least a mechanism argument ("
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick AP_ALL_AVAILABLE_MUTEXES_STRING ")";
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick rv = ap_parse_mutex(mechdir, p, &mech, &mutexdir);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (rv == APR_ENOTIMPL) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return apr_pstrcat(p, "Invalid Mutex argument ", mechdir,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick " (" AP_ALL_AVAILABLE_MUTEXES_STRING ")", NULL);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick else if (rv == APR_BADARG
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick || (mutexdir && !ap_is_directory(p, mutexdir))) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return apr_pstrcat(p, "Invalid Mutex directory in argument ",
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick mechdir, NULL);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick else if (rv == APR_ENOLOCK) { /* "none" */
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick no_mutex = 1;
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick }
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick /* "OmitPID" can appear at the end of the list, so build a list of
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick * mutex type names while looking for "OmitPID" (anywhere) or the end
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick */
b6b8c27b2adcf08eca23d3b7c2de79880b816a57takashi type_list = apr_array_make(cmd->pool, 4, sizeof(const char *));
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick while (*arg) {
b6b8c27b2adcf08eca23d3b7c2de79880b816a57takashi const char *s = ap_getword_conf(cmd->pool, &arg);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick if (!strcasecmp(s, "omitpid")) {
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick omit_pid = 1;
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick }
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick else {
b6b8c27b2adcf08eca23d3b7c2de79880b816a57takashi const char **new_type = (const char **)apr_array_push(type_list);
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick *new_type = s;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick if (apr_is_empty_array(type_list)) { /* no mutex type? assume "default" */
b6b8c27b2adcf08eca23d3b7c2de79880b816a57takashi const char **new_type = (const char **)apr_array_push(type_list);
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick *new_type = "default";
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick }
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick while ((elt = (const char **)apr_array_pop(type_list)) != NULL) {
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick const char *type = *elt;
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick mxcfg = apr_hash_get(mxcfg_by_type, type, APR_HASH_KEY_STRING);
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick if (!mxcfg) {
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick return apr_psprintf(p, "Mutex type %s is not valid", type);
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick }
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick mxcfg->none = 0; /* in case that was the default */
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick mxcfg->omit_pid = omit_pid;
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick mxcfg->set = 1;
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick if (no_mutex) {
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick if (!(mxcfg->options & AP_MUTEX_ALLOW_NONE)) {
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick return apr_psprintf(p,
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick "None is not allowed for mutex type %s",
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick type);
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick }
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick mxcfg->none = 1;
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick }
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick else {
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick mxcfg->mech = mech;
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick if (mutexdir) { /* retain mutex default if not configured */
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick mxcfg->dir = mutexdir;
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return NULL;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick}
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawickAP_DECLARE(apr_status_t) ap_mutex_register(apr_pool_t *pconf,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick const char *type,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick const char *default_dir,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick apr_lockmech_e default_mech,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick apr_int32_t options)
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick{
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick mutex_cfg_t *mxcfg = apr_pcalloc(pconf, sizeof *mxcfg);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if ((options & ~(AP_MUTEX_ALLOW_NONE | AP_MUTEX_DEFAULT_NONE))) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return APR_EINVAL;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
ead0b57bbeaec5acb14f931b5641962f429dabc9trawick ap_mutex_init(pconf); /* in case this mod's pre-config ran before core's */
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick mxcfg->options = options;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (options & AP_MUTEX_DEFAULT_NONE) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick mxcfg->none = 1;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick mxcfg->dir = default_dir; /* usually NULL */
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick mxcfg->mech = default_mech; /* usually APR_LOCK_DEFAULT */
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick apr_hash_set(mxcfg_by_type, type, APR_HASH_KEY_STRING, mxcfg);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return APR_SUCCESS;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick}
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawickstatic int mutex_needs_file(apr_lockmech_e mech)
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick{
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (mech != APR_LOCK_FLOCK
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick && mech != APR_LOCK_FCNTL
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick#if APR_USE_FLOCK_SERIALIZE || APR_USE_FCNTL_SERIALIZE
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick && mech != APR_LOCK_DEFAULT
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick#endif
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick ) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return 0;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return 1;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick}
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawickstatic const char *get_mutex_filename(apr_pool_t *p, mutex_cfg_t *mxcfg,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick const char *type,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick const char *instance_id)
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick{
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick const char *pid_suffix = "";
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (!mutex_needs_file(mxcfg->mech)) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return NULL;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick#if HAVE_UNISTD_H
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick if (!mxcfg->omit_pid) {
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick pid_suffix = apr_psprintf(p, ".%" APR_PID_T_FMT, getpid());
2b6c7b8eb5fbc43564898aedac730df7e91da475trawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick#endif
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
0fdcfd7a51bf3028b0be879c43c009c16c6d3f58trawick return ap_runtime_dir_relative(p,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick apr_pstrcat(p,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick mxcfg->dir,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick "/",
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick type,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick instance_id ? "-" : "",
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick instance_id ? instance_id : "",
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick pid_suffix,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick NULL));
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick}
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawickstatic mutex_cfg_t *mxcfg_lookup(apr_pool_t *p, const char *type)
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick{
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick mutex_cfg_t *defcfg, *mxcfg, *newcfg;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick defcfg = apr_hash_get(mxcfg_by_type, "default", APR_HASH_KEY_STRING);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick /* MUST exist in table, or wasn't registered */
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick mxcfg = apr_hash_get(mxcfg_by_type, type, APR_HASH_KEY_STRING);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (!mxcfg) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return NULL;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick /* order of precedence:
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick * 1. Mutex directive for this mutex
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick * 2. Mutex directive for "default"
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick * 3. Defaults for this mutex from ap_mutex_register()
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick * 4. Global defaults
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick */
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (mxcfg->set) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick newcfg = mxcfg;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick else if (defcfg->set) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick newcfg = defcfg;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick else if (mxcfg->none || mxcfg->mech != APR_LOCK_DEFAULT) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick newcfg = mxcfg;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick else {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick newcfg = defcfg;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (!newcfg->none && mutex_needs_file(newcfg->mech) && !newcfg->dir) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick /* a file-based mutex mechanism was configured, but
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick * without a mutex file directory; go back through
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick * the chain to find the directory, store in new
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick * mutex cfg structure
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick */
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick newcfg = apr_pmemdup(p, newcfg, sizeof *newcfg);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick /* !true if dir not already set: mxcfg->set && defcfg->dir */
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (defcfg->set && defcfg->dir) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick newcfg->dir = defcfg->dir;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick else if (mxcfg->dir) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick newcfg->dir = mxcfg->dir;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick else {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick newcfg->dir = defcfg->dir;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return newcfg;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick}
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawickstatic void log_bad_create_options(server_rec *s, const char *type)
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick{
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(00021)
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick "Invalid options were specified when creating the %s mutex",
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick type);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick}
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawickstatic void log_unknown_type(server_rec *s, const char *type)
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick{
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(00022)
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick "Can't create mutex of unknown type %s", type);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick}
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawickstatic void log_create_failure(apr_status_t rv, server_rec *s, const char *type,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick const char *fname)
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick{
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(00023)
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick "Couldn't create the %s mutex %s%s%s", type,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick fname ? "(file " : "",
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick fname ? fname : "",
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick fname ? ")" : "");
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick}
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
34b815d39cbd4d04c012409f333442568311788etrawick#ifdef AP_NEED_SET_MUTEX_PERMS
11f2c481e1d57bedb3f758565307501e9a2730ddtrawickstatic void log_perms_failure(apr_status_t rv, server_rec *s, const char *type)
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick{
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(00024)
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick "Couldn't set permissions on the %s mutex; "
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick "check User and Group directives",
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick type);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick}
34b815d39cbd4d04c012409f333442568311788etrawick#endif
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawickAP_DECLARE(apr_status_t) ap_global_mutex_create(apr_global_mutex_t **mutex,
6a00621903eff76c1a3ebc3ee46f5e59a492bf77wrowe const char **name,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick const char *type,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick const char *instance_id,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick server_rec *s, apr_pool_t *p,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick apr_int32_t options)
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick{
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick apr_status_t rv;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick const char *fname;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick mutex_cfg_t *mxcfg = mxcfg_lookup(p, type);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (options) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick log_bad_create_options(s, type);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return APR_EINVAL;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (!mxcfg) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick log_unknown_type(s, type);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return APR_EINVAL;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (mxcfg->none) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick *mutex = NULL;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return APR_SUCCESS;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick fname = get_mutex_filename(p, mxcfg, type, instance_id);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick rv = apr_global_mutex_create(mutex, fname, mxcfg->mech, p);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (rv != APR_SUCCESS) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick log_create_failure(rv, s, type, fname);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return rv;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
6a00621903eff76c1a3ebc3ee46f5e59a492bf77wrowe if (name)
6a00621903eff76c1a3ebc3ee46f5e59a492bf77wrowe *name = fname;
6a00621903eff76c1a3ebc3ee46f5e59a492bf77wrowe
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick#ifdef AP_NEED_SET_MUTEX_PERMS
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick rv = ap_unixd_set_global_mutex_perms(*mutex);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (rv != APR_SUCCESS) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick log_perms_failure(rv, s, type);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick#endif
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
6a00621903eff76c1a3ebc3ee46f5e59a492bf77wrowe return rv;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick}
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawickAP_DECLARE(apr_status_t) ap_proc_mutex_create(apr_proc_mutex_t **mutex,
6a00621903eff76c1a3ebc3ee46f5e59a492bf77wrowe const char **name,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick const char *type,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick const char *instance_id,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick server_rec *s, apr_pool_t *p,
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick apr_int32_t options)
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick{
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick apr_status_t rv;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick const char *fname;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick mutex_cfg_t *mxcfg = mxcfg_lookup(p, type);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (options) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick log_bad_create_options(s, type);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return APR_EINVAL;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (!mxcfg) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick log_unknown_type(s, type);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return APR_EINVAL;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (mxcfg->none) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick *mutex = NULL;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return APR_SUCCESS;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick fname = get_mutex_filename(p, mxcfg, type, instance_id);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick rv = apr_proc_mutex_create(mutex, fname, mxcfg->mech, p);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (rv != APR_SUCCESS) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick log_create_failure(rv, s, type, fname);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick return rv;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
6a00621903eff76c1a3ebc3ee46f5e59a492bf77wrowe if (name)
6a00621903eff76c1a3ebc3ee46f5e59a492bf77wrowe *name = fname;
6a00621903eff76c1a3ebc3ee46f5e59a492bf77wrowe
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick#ifdef AP_NEED_SET_MUTEX_PERMS
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick rv = ap_unixd_set_proc_mutex_perms(*mutex);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick if (rv != APR_SUCCESS) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick log_perms_failure(rv, s, type);
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick }
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick#endif
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick
6a00621903eff76c1a3ebc3ee46f5e59a492bf77wrowe return rv;
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick}
67746e0d18eeceb247fc940148c9b4d358929643sf
67746e0d18eeceb247fc940148c9b4d358929643sfAP_CORE_DECLARE(void) ap_dump_mutexes(apr_pool_t *p, server_rec *s, apr_file_t *out)
67746e0d18eeceb247fc940148c9b4d358929643sf{
67746e0d18eeceb247fc940148c9b4d358929643sf apr_hash_index_t *idx;
67746e0d18eeceb247fc940148c9b4d358929643sf mutex_cfg_t *defcfg = apr_hash_get(mxcfg_by_type, "default", APR_HASH_KEY_STRING);
67746e0d18eeceb247fc940148c9b4d358929643sf for (idx = apr_hash_first(p, mxcfg_by_type); idx; idx = apr_hash_next(idx))
67746e0d18eeceb247fc940148c9b4d358929643sf {
67746e0d18eeceb247fc940148c9b4d358929643sf mutex_cfg_t *mxcfg;
67746e0d18eeceb247fc940148c9b4d358929643sf const char *name, *mech;
67746e0d18eeceb247fc940148c9b4d358929643sf const void *name_;
67746e0d18eeceb247fc940148c9b4d358929643sf const char *dir = "";
67746e0d18eeceb247fc940148c9b4d358929643sf apr_hash_this(idx, &name_, NULL, NULL);
67746e0d18eeceb247fc940148c9b4d358929643sf name = name_;
67746e0d18eeceb247fc940148c9b4d358929643sf mxcfg = mxcfg_lookup(p, name);
67746e0d18eeceb247fc940148c9b4d358929643sf if (mxcfg == defcfg && strcmp(name, "default") != 0) {
67746e0d18eeceb247fc940148c9b4d358929643sf apr_file_printf(out, "Mutex %s: using_defaults\n", name);
67746e0d18eeceb247fc940148c9b4d358929643sf continue;
67746e0d18eeceb247fc940148c9b4d358929643sf }
67746e0d18eeceb247fc940148c9b4d358929643sf if (mxcfg->none) {
67746e0d18eeceb247fc940148c9b4d358929643sf apr_file_printf(out, "Mutex %s: none\n", name);
67746e0d18eeceb247fc940148c9b4d358929643sf continue;
67746e0d18eeceb247fc940148c9b4d358929643sf }
67746e0d18eeceb247fc940148c9b4d358929643sf switch (mxcfg->mech) {
67746e0d18eeceb247fc940148c9b4d358929643sf case APR_LOCK_DEFAULT:
67746e0d18eeceb247fc940148c9b4d358929643sf mech = "default";
67746e0d18eeceb247fc940148c9b4d358929643sf break;
67746e0d18eeceb247fc940148c9b4d358929643sf#if APR_HAS_FCNTL_SERIALIZE
67746e0d18eeceb247fc940148c9b4d358929643sf case APR_LOCK_FCNTL:
67746e0d18eeceb247fc940148c9b4d358929643sf mech = "fcntl";
67746e0d18eeceb247fc940148c9b4d358929643sf break;
67746e0d18eeceb247fc940148c9b4d358929643sf#endif
67746e0d18eeceb247fc940148c9b4d358929643sf#if APR_HAS_FLOCK_SERIALIZE
67746e0d18eeceb247fc940148c9b4d358929643sf case APR_LOCK_FLOCK:
67746e0d18eeceb247fc940148c9b4d358929643sf mech = "flock";
67746e0d18eeceb247fc940148c9b4d358929643sf break;
67746e0d18eeceb247fc940148c9b4d358929643sf#endif
67746e0d18eeceb247fc940148c9b4d358929643sf#if APR_HAS_POSIXSEM_SERIALIZE
67746e0d18eeceb247fc940148c9b4d358929643sf case APR_LOCK_POSIXSEM:
67746e0d18eeceb247fc940148c9b4d358929643sf mech = "posixsem";
67746e0d18eeceb247fc940148c9b4d358929643sf break;
67746e0d18eeceb247fc940148c9b4d358929643sf#endif
67746e0d18eeceb247fc940148c9b4d358929643sf#if APR_HAS_SYSVSEM_SERIALIZE
67746e0d18eeceb247fc940148c9b4d358929643sf case APR_LOCK_SYSVSEM:
67746e0d18eeceb247fc940148c9b4d358929643sf mech = "sysvsem";
67746e0d18eeceb247fc940148c9b4d358929643sf break;
67746e0d18eeceb247fc940148c9b4d358929643sf#endif
67746e0d18eeceb247fc940148c9b4d358929643sf#if APR_HAS_PROC_PTHREAD_SERIALIZE
67746e0d18eeceb247fc940148c9b4d358929643sf case APR_LOCK_PROC_PTHREAD:
67746e0d18eeceb247fc940148c9b4d358929643sf mech = "pthread";
67746e0d18eeceb247fc940148c9b4d358929643sf break;
67746e0d18eeceb247fc940148c9b4d358929643sf#endif
67746e0d18eeceb247fc940148c9b4d358929643sf default:
67746e0d18eeceb247fc940148c9b4d358929643sf ap_assert(0);
67746e0d18eeceb247fc940148c9b4d358929643sf }
67746e0d18eeceb247fc940148c9b4d358929643sf
67746e0d18eeceb247fc940148c9b4d358929643sf if (mxcfg->dir)
0fdcfd7a51bf3028b0be879c43c009c16c6d3f58trawick dir = ap_runtime_dir_relative(p, mxcfg->dir);
67746e0d18eeceb247fc940148c9b4d358929643sf
67746e0d18eeceb247fc940148c9b4d358929643sf apr_file_printf(out, "Mutex %s: dir=\"%s\" mechanism=%s %s\n", name, dir, mech,
67746e0d18eeceb247fc940148c9b4d358929643sf mxcfg->omit_pid ? "[OmitPid]" : "");
67746e0d18eeceb247fc940148c9b4d358929643sf }
67746e0d18eeceb247fc940148c9b4d358929643sf}