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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * util_mutex.c: Useful functions for determining allowable
19 * mutexes and mutex settings
24 #include "apr_strings.h"
27 #define APR_WANT_STRFUNC
32 #include "ap_config.h"
34 #include "http_main.h"
35 #include "http_config.h"
36 #include "util_mutex.h"
38 AP_DECLARE(apr_status_t) ap_parse_mutex(const char *arg, apr_pool_t *pool,
39 apr_lockmech_e *mutexmech,
40 const char **mutexfile)
42 /* Split arg into meth and file */
43 char *meth = apr_pstrdup(pool, arg);
44 char *file = strchr(meth, ':');
52 if (!strcasecmp(meth, "none") || !strcasecmp(meth, "no")) {
56 /* APR determines temporary filename unless overridden below,
57 * we presume file indicates an mutexfile is a file path
58 * unless the method sets mutexfile=file and NULLs file
62 /* NOTE: previously, 'yes' implied 'sem' */
63 if (!strcasecmp(meth, "default") || !strcasecmp(meth, "yes")) {
64 *mutexmech = APR_LOCK_DEFAULT;
66 #if APR_HAS_FCNTL_SERIALIZE
67 else if (!strcasecmp(meth, "fcntl") || !strcasecmp(meth, "file")) {
68 *mutexmech = APR_LOCK_FCNTL;
71 #if APR_HAS_FLOCK_SERIALIZE
72 else if (!strcasecmp(meth, "flock") || !strcasecmp(meth, "file")) {
73 *mutexmech = APR_LOCK_FLOCK;
76 #if APR_HAS_POSIXSEM_SERIALIZE
77 else if (!strcasecmp(meth, "posixsem") || !strcasecmp(meth, "sem")) {
78 *mutexmech = APR_LOCK_POSIXSEM;
79 /* Posix/SysV semaphores aren't file based, use the literal name
80 * if provided and fall back on APR's default if not. Today, APR
81 * will ignore it, but once supported it has an absurdly short limit.
84 *mutexfile = apr_pstrdup(pool, file);
90 #if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)
91 else if (!strcasecmp(meth, "sysvsem") || !strcasecmp(meth, "sem")) {
92 *mutexmech = APR_LOCK_SYSVSEM;
95 #if APR_HAS_PROC_PTHREAD_SERIALIZE
96 else if (!strcasecmp(meth, "pthread")) {
97 *mutexmech = APR_LOCK_PROC_PTHREAD;
104 /* Unless the method above assumed responsibility for setting up
105 * mutexfile and NULLing out file, presume it is a file we
109 *mutexfile = ap_server_root_relative(pool, file);