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
30 #include "ap_config.h"
32 #include "http_main.h"
33 #include "http_config.h"
34 #include "util_mutex.h"
36 AP_DECLARE(apr_status_t
) ap_parse_mutex(const char *arg
, apr_pool_t
*pool
,
37 apr_lockmech_e
*mutexmech
,
38 const char **mutexfile
)
40 /* Split arg into meth and file */
41 char *meth
= apr_pstrdup(pool
, arg
);
42 char *file
= strchr(meth
, ':');
50 if (!strcasecmp(meth
, "none") || !strcasecmp(meth
, "no")) {
54 /* APR determines temporary filename unless overridden below,
55 * we presume file indicates an mutexfile is a file path
56 * unless the method sets mutexfile=file and NULLs file
60 /* NOTE: previously, 'yes' implied 'sem' */
61 if (!strcasecmp(meth
, "default") || !strcasecmp(meth
, "yes")) {
62 *mutexmech
= APR_LOCK_DEFAULT
;
64 #if APR_HAS_FCNTL_SERIALIZE
65 else if (!strcasecmp(meth
, "fcntl") || !strcasecmp(meth
, "file")) {
66 *mutexmech
= APR_LOCK_FCNTL
;
69 #if APR_HAS_FLOCK_SERIALIZE
70 else if (!strcasecmp(meth
, "flock") || !strcasecmp(meth
, "file")) {
71 *mutexmech
= APR_LOCK_FLOCK
;
74 #if APR_HAS_POSIXSEM_SERIALIZE
75 else if (!strcasecmp(meth
, "posixsem") || !strcasecmp(meth
, "sem")) {
76 *mutexmech
= APR_LOCK_POSIXSEM
;
77 /* Posix/SysV semaphores aren't file based, use the literal name
78 * if provided and fall back on APR's default if not. Today, APR
79 * will ignore it, but once supported it has an absurdly short limit.
82 *mutexfile
= apr_pstrdup(pool
, file
);
88 #if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)
89 else if (!strcasecmp(meth
, "sysvsem") || !strcasecmp(meth
, "sem")) {
90 *mutexmech
= APR_LOCK_SYSVSEM
;
93 #if APR_HAS_PROC_PTHREAD_SERIALIZE
94 else if (!strcasecmp(meth
, "pthread")) {
95 *mutexmech
= APR_LOCK_PROC_PTHREAD
;
102 /* Unless the method above assumed responsibility for setting up
103 * mutexfile and NULLing out file, presume it is a file we
107 *mutexfile
= ap_server_root_relative(pool
, file
);