]> granicus.if.org Git - apache/blob - server/util_mutex.c
Brind OS/2 MPM up to date with current API.
[apache] / server / util_mutex.c
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /*
18  * util_mutex.c: Useful functions for determining allowable
19  *               mutexes and mutex settings
20  */
21
22
23 #include "apr.h"
24 #include "apr_strings.h"
25 #include "apr_lib.h"
26
27 #define APR_WANT_STRFUNC
28 #include "apr_want.h"
29
30 #include "ap_config.h"
31 #include "httpd.h"
32 #include "http_main.h"
33 #include "http_config.h"
34 #include "util_mutex.h"
35
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)
39 {
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;
47         }
48     }
49
50     if (!strcasecmp(meth, "none") || !strcasecmp(meth, "no")) {
51         return APR_ENOLOCK;
52     }
53
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
57      */
58     *mutexfile = NULL;
59
60     /* NOTE: previously, 'yes' implied 'sem' */
61     if (!strcasecmp(meth, "default") || !strcasecmp(meth, "yes")) {
62         *mutexmech = APR_LOCK_DEFAULT;
63     }
64 #if APR_HAS_FCNTL_SERIALIZE
65     else if (!strcasecmp(meth, "fcntl") || !strcasecmp(meth, "file")) {
66         *mutexmech = APR_LOCK_FCNTL;
67     }
68 #endif
69 #if APR_HAS_FLOCK_SERIALIZE
70     else if (!strcasecmp(meth, "flock") || !strcasecmp(meth, "file")) {
71         *mutexmech = APR_LOCK_FLOCK;
72     }
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.
80          */
81         if (file) {
82             *mutexfile = apr_pstrdup(pool, file);
83
84             file = NULL;
85         }
86     }
87 #endif
88 #if APR_HAS_SYSVSEM_SERIALIZE
89     else if (!strcasecmp(meth, "sysvsem") || !strcasecmp(meth, "sem")) {
90         *mutexmech = APR_LOCK_SYSVSEM;
91     }
92 #endif
93 #if APR_HAS_PROC_PTHREAD_SERIALIZE
94     else if (!strcasecmp(meth, "pthread")) {
95         *mutexmech = APR_LOCK_PROC_PTHREAD;
96     }
97 #endif
98     else {
99         return APR_ENOTIMPL;
100     }
101
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
105      */
106     if (file) {
107         *mutexfile = ap_server_root_relative(pool, file);
108         if (!*mutexfile) {
109             return APR_BADARG;
110         }
111     }
112
113     return APR_SUCCESS;
114 }