removed some of the debug logging and added author details
[httpd-crcsyncproxy.git] / server / util_mutex.c
blob1ea02ccb1b908da8a84355f761555d6cc096a8dd
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
23 #include "apr.h"
24 #include "apr_strings.h"
25 #include "apr_lib.h"
27 #define APR_WANT_STRFUNC
28 #include "apr_want.h"
30 #include "ap_config.h"
31 #include "httpd.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, ':');
43 if (file) {
44 *(file++) = '\0';
45 if (!*file) {
46 file = NULL;
50 if (!strcasecmp(meth, "none") || !strcasecmp(meth, "no")) {
51 return APR_ENOLOCK;
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
58 *mutexfile = NULL;
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;
68 #endif
69 #if APR_HAS_FLOCK_SERIALIZE
70 else if (!strcasecmp(meth, "flock") || !strcasecmp(meth, "file")) {
71 *mutexmech = APR_LOCK_FLOCK;
73 #endif
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.
81 if (file) {
82 *mutexfile = apr_pstrdup(pool, file);
84 file = NULL;
87 #endif
88 #if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)
89 else if (!strcasecmp(meth, "sysvsem") || !strcasecmp(meth, "sem")) {
90 *mutexmech = APR_LOCK_SYSVSEM;
92 #endif
93 #if APR_HAS_PROC_PTHREAD_SERIALIZE
94 else if (!strcasecmp(meth, "pthread")) {
95 *mutexmech = APR_LOCK_PROC_PTHREAD;
97 #endif
98 else {
99 return APR_ENOTIMPL;
102 /* Unless the method above assumed responsibility for setting up
103 * mutexfile and NULLing out file, presume it is a file we
104 * are looking to use
106 if (file) {
107 *mutexfile = ap_server_root_relative(pool, file);
108 if (!*mutexfile) {
109 return APR_BADARG;
113 return APR_SUCCESS;