]> granicus.if.org Git - apache/blob - server/util_mutex.c
mod_session_cookie: Add a session implementation capable of storing
[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 #define CORE_PRIVATE
31
32 #include "ap_config.h"
33 #include "httpd.h"
34 #include "http_main.h"
35 #include "http_config.h"
36 #include "util_mutex.h"
37
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)
41 {
42     /* Split arg into meth and file */
43     char *meth = apr_pstrdup(pool, arg);
44     char *file = strchr(meth, ':');
45     if (file) {
46         *(file++) = '\0';
47         if (!*file) {
48             file = NULL;
49         }
50     }
51
52     if (!strcasecmp(meth, "none") || !strcasecmp(meth, "no")) {
53         return APR_ENOLOCK;
54     }
55
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
59      */
60     *mutexfile = NULL;
61
62     /* NOTE: previously, 'yes' implied 'sem' */
63     if (!strcasecmp(meth, "default") || !strcasecmp(meth, "yes")) {
64         *mutexmech = APR_LOCK_DEFAULT;
65     }
66 #if APR_HAS_FCNTL_SERIALIZE
67     else if (!strcasecmp(meth, "fcntl") || !strcasecmp(meth, "file")) {
68         *mutexmech = APR_LOCK_FCNTL;
69     }
70 #endif
71 #if APR_HAS_FLOCK_SERIALIZE
72     else if (!strcasecmp(meth, "flock") || !strcasecmp(meth, "file")) {
73         *mutexmech = APR_LOCK_FLOCK;
74     }
75 #endif
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.
82          */
83         if (file) {
84             *mutexfile = apr_pstrdup(pool, file);
85
86             file = NULL;
87         }
88     }
89 #endif
90 #if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)
91     else if (!strcasecmp(meth, "sysvsem") || !strcasecmp(meth, "sem")) {
92         *mutexmech = APR_LOCK_SYSVSEM;
93     }
94 #endif
95 #if APR_HAS_PROC_PTHREAD_SERIALIZE
96     else if (!strcasecmp(meth, "pthread")) {
97         *mutexmech = APR_LOCK_PROC_PTHREAD;
98     }
99 #endif
100     else {
101         return APR_ENOTIMPL;
102     }
103
104     /* Unless the method above assumed responsibility for setting up
105      * mutexfile and NULLing out file, presume it is a file we
106      * are looking to use
107      */
108     if (file) {
109         *mutexfile = ap_server_root_relative(pool, file);
110         if (!*mutexfile) {
111             return APR_BADARG;
112         }
113     }
114
115     return APR_SUCCESS;
116 }