Apache HTTPD
apu_dso.c
Go to the documentation of this file.
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#include <ctype.h>
18#include <stdio.h>
19
20#include "apu_config.h"
21#include "apu.h"
22
23#include "apr_pools.h"
24#include "apr_tables.h"
25#include "apr_dso.h"
26#include "apr_strings.h"
27#include "apr_hash.h"
28#include "apr_file_io.h"
29#include "apr_env.h"
30#include "apr_atomic.h"
31
32#include "apu_internal.h"
33#include "apu_version.h"
34
35#if APU_DSO_BUILD
36
37#if APR_HAS_THREADS
38static apr_thread_mutex_t* mutex = NULL;
39#endif
40static apr_hash_t *dsos = NULL;
41static apr_uint32_t initialised = 0, in_init = 1;
42
43#if APR_HAS_THREADS
45{
46 return apr_thread_mutex_lock(mutex);
47}
49{
50 return apr_thread_mutex_unlock(mutex);
51}
52#else
54 return APR_SUCCESS;
55}
57 return APR_SUCCESS;
58}
59#endif
60
61static apr_status_t apu_dso_term(void *ptr)
62{
63 /* set statics to NULL so init can work again */
64 dsos = NULL;
65#if APR_HAS_THREADS
66 mutex = NULL;
67#endif
68
69 /* Everything else we need is handled by cleanups registered
70 * when we created mutexes and loaded DSOs
71 */
72 return APR_SUCCESS;
73}
74
76{
79
81 apr_atomic_set32(&initialised, 1); /* prevent wrap-around */
82
83 while (apr_atomic_read32(&in_init)) /* wait until we get fully inited */
84 ;
85
86 return APR_SUCCESS;
87 }
88
89 /* Top level pool scope, need process-scope lifetime */
91 parent && parent != pool;
93 pool = parent;
94
96
97#if APR_HAS_THREADS
99 /* This already registers a pool cleanup */
100#endif
101
104
106
107 return ret;
108}
109
112 const char *module,
113 const char *modsym,
115{
117 char *pathlist;
118 char path[APR_PATH_MAX + 1];
120 apr_pool_t *global;
122 char *eos = NULL;
123 int i;
124
126 if (*dsoptr) {
127 return APR_EINIT;
128 }
129
130 /* The driver DSO must have exactly the same lifetime as the
131 * drivers hash table; ignore the passed-in pool */
132 global = apr_hash_pool_get(dsos);
133
134 /* Retrieve our path search list or prepare for a single search */
137 paths = apr_array_make(pool, 1, sizeof(char*));
138
139#if defined(APU_DSO_LIBDIR)
140 /* Always search our prefix path, but on some platforms such as
141 * win32 this may be left undefined
142 */
143 (*((char **)apr_array_push(paths))) = APU_DSO_LIBDIR;
144#endif
145
146 for (i = 0; i < paths->nelts; ++i)
147 {
148#if defined(WIN32)
149 /* Use win32 dso search semantics and attempt to
150 * load the relative lib on the first pass.
151 */
152 if (!eos) {
153 eos = path;
154 --i;
155 }
156 else
157#endif
158 {
159 eos = apr_cpystrn(path, ((char**)paths->elts)[i], sizeof(path));
160 if ((eos > path) && (eos - path < sizeof(path) - 1))
161 *(eos++) = '/';
162 }
163 apr_cpystrn(eos, module, sizeof(path) - (eos - path));
164
165 rv = apr_dso_load(&dlhandle, path, global);
166 if (dlhandleptr) {
168 }
169 if (rv == APR_SUCCESS) { /* APR_EDSOOPEN */
170 break;
171 }
172#if defined(APU_DSO_LIBDIR)
173 else if (i < paths->nelts - 1) {
174#else
175 else { /* No APU_DSO_LIBDIR to skip */
176#endif
177 /* try with apr-util-APU_MAJOR_VERSION appended */
179 "apr-util-" APU_STRINGIFY(APU_MAJOR_VERSION) "/",
180 sizeof(path) - (eos - path));
181
182 apr_cpystrn(eos, module, sizeof(path) - (eos - path));
183
184 rv = apr_dso_load(&dlhandle, path, global);
185 if (dlhandleptr) {
187 }
188 if (rv == APR_SUCCESS) { /* APR_EDSOOPEN */
189 break;
190 }
191 }
192 }
193
194 if (rv != APR_SUCCESS) /* APR_ESYMNOTFOUND */
195 return rv;
196
198 if (rv != APR_SUCCESS) { /* APR_ESYMNOTFOUND */
200 }
201 else {
202 module = apr_pstrdup(global, module);
204 }
205 return rv;
206}
207
208#endif /* APU_DSO_BUILD */
209
APR Atomic Operations.
static apr_uint32_t initialised
Definition apr_dbd.c:37
static apr_uint32_t in_init
Definition apr_dbd.c:37
APR Dynamic Object Handling Routines.
APR Environment functions.
APR File I/O Handling.
APR Hash Tables.
APR memory allocation.
APR Strings library.
APR Table library.
APR-util Versioning Interface.
#define APU_STRINGIFY(n)
Definition apu_version.h:87
#define APU_MAJOR_VERSION
Definition apu_version.h:53
apr_uint32_t apr_atomic_inc32(volatile apr_uint32_t *mem)
Definition atomic.c:51
int apr_atomic_dec32(volatile apr_uint32_t *mem)
Definition atomic.c:56
void apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
Definition atomic.c:73
apr_uint32_t apr_atomic_read32(volatile apr_uint32_t *mem)
Definition atomic.c:68
request_rec int int apr_table_t const char * path
#define APR_EINIT
Definition apr_errno.h:474
#define APR_EDSOOPEN
Definition apr_errno.h:322
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
#define APR_HASH_KEY_STRING
Definition apr_hash.h:47
apr_pool_t * parent
Definition apr_pools.h:197
int nelts
Definition apr_tables.h:122
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347