mod_so.c revision b2c17021012bc4f7cd8e374c6bd72b926737320f
b66914021bd429f41311d2909a7e9289866da7fdnd/* Licensed to the Apache Software Foundation (ASF) under one or more
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd * contributor license agreements. See the NOTICE file distributed with
9963f91528694fb21e93da8584c31f226c6de97akess * this work for additional information regarding copyright ownership.
b66914021bd429f41311d2909a7e9289866da7fdnd * The ASF licenses this file to You under the Apache License, Version 2.0
b66914021bd429f41311d2909a7e9289866da7fdnd * (the "License"); you may not use this file except in compliance with
031b91a62d25106ae69d4693475c79618dd5e884fielding * the License. You may obtain a copy of the License at
031b91a62d25106ae69d4693475c79618dd5e884fielding * Unless required by applicable law or agreed to in writing, software
031b91a62d25106ae69d4693475c79618dd5e884fielding * distributed under the License is distributed on an "AS IS" BASIS,
b66914021bd429f41311d2909a7e9289866da7fdnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
b66914021bd429f41311d2909a7e9289866da7fdnd * See the License for the specific language governing permissions and
b66914021bd429f41311d2909a7e9289866da7fdnd * limitations under the License.
b66914021bd429f41311d2909a7e9289866da7fdnd * This module is used to load Apache modules at runtime. This means that the
b66914021bd429f41311d2909a7e9289866da7fdnd * server functionality can be extended without recompiling and even without
b66914021bd429f41311d2909a7e9289866da7fdnd * taking the server down at all. Only a HUP or AP_SIG_GRACEFUL signal
b66914021bd429f41311d2909a7e9289866da7fdnd * needs to be sent to the server to reload the dynamically loaded modules.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * To use, you'll first need to build your module as a shared library, then
eed2a23d9b5986937f1e2b1c120be97744508a72nd * update your configuration (httpd.conf) to get the Apache core to load the
eed2a23d9b5986937f1e2b1c120be97744508a72nd * module at start-up.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * The easiest way to build a module as a shared library is to use the
eed2a23d9b5986937f1e2b1c120be97744508a72nd * `SharedModule' command in the Configuration file, instead of `AddModule'.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * You should also change the file extension from `.o' to `.so'. So, for
eed2a23d9b5986937f1e2b1c120be97744508a72nd * example, to build the status module as a shared library edit Configuration
eed2a23d9b5986937f1e2b1c120be97744508a72nd * and change
eed2a23d9b5986937f1e2b1c120be97744508a72nd * SharedModule modules/standard/mod_status.so
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Run Configure and make. Now Apache's httpd binary will _not_ include
eed2a23d9b5986937f1e2b1c120be97744508a72nd * mod_status. Instead a shared object called mod_status.so will be build, in
eed2a23d9b5986937f1e2b1c120be97744508a72nd * the modules/standard directory. You can build most of the modules as shared
eed2a23d9b5986937f1e2b1c120be97744508a72nd * libraries like this.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * To use the shared module, move the .so file(s) into an appropriate
eed2a23d9b5986937f1e2b1c120be97744508a72nd * directory. You might like to create a directory called "modules" under you
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Then edit your conf/httpd.conf file, and add LoadModule lines. For
eed2a23d9b5986937f1e2b1c120be97744508a72nd * LoadModule status_module modules/mod_status.so
eed2a23d9b5986937f1e2b1c120be97744508a72nd * The first argument is the module's structure name (look at the end of the
eed2a23d9b5986937f1e2b1c120be97744508a72nd * module source to find this). The second option is the path to the module
eed2a23d9b5986937f1e2b1c120be97744508a72nd * file, relative to the server root. Put these directives right at the top
eed2a23d9b5986937f1e2b1c120be97744508a72nd * of your httpd.conf file.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Now you can start Apache. A message will be logged at "debug" level to your
eed2a23d9b5986937f1e2b1c120be97744508a72nd * error_log to confirm that the module(s) are loaded (use "LogLevel debug"
eed2a23d9b5986937f1e2b1c120be97744508a72nd * directive to get these log messages).
eed2a23d9b5986937f1e2b1c120be97744508a72nd * If you edit the LoadModule directives while the server is live you can get
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Apache to re-load the modules by sending it a HUP or AP_SIG_GRACEFUL
eed2a23d9b5986937f1e2b1c120be97744508a72nd * signal as normal. You can use this to dynamically change the capability
eed2a23d9b5986937f1e2b1c120be97744508a72nd * of your server without bringing it down.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Because currently there is only limited builtin support in the Configure
eed2a23d9b5986937f1e2b1c120be97744508a72nd * script for creating the shared library files (`.so'), please consult your
eed2a23d9b5986937f1e2b1c120be97744508a72nd * vendors cc(1), ld(1) and dlopen(3) manpages to find out the appropriate
eed2a23d9b5986937f1e2b1c120be97744508a72nd * compiler and linker flags and insert them manually into the Configuration
eed2a23d9b5986937f1e2b1c120be97744508a72nd * file under CFLAGS_SHLIB, LDFLAGS_SHLIB and LDFLAGS_SHLIB_EXPORT.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * If you still have problems figuring out the flags both try the paper
eed2a23d9b5986937f1e2b1c120be97744508a72nd * http://developer.netscape.com/library/documentation/enterprise
eed2a23d9b5986937f1e2b1c120be97744508a72nd * or install a Perl 5 interpreter on your platform and then run the command
eed2a23d9b5986937f1e2b1c120be97744508a72nd * $ perl -V:usedl -V:ccdlflags -V:cccdlflags -V:lddlflags
eed2a23d9b5986937f1e2b1c120be97744508a72nd * This gives you what type of dynamic loading Perl 5 uses on your platform
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd * and which compiler and linker flags Perl 5 uses to create the shared object
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd * Another location where you can find useful hints is the `ltconfig' script
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd * of the GNU libtool 1.2 package. Search for your platform name inside the
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd * various "case" constructs.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Server configuration to keep track of actually
9963f91528694fb21e93da8584c31f226c6de97akess * loaded modules and the corresponding module name.
eed2a23d9b5986937f1e2b1c120be97744508a72ndtypedef struct so_server_conf {
eed2a23d9b5986937f1e2b1c120be97744508a72ndstatic void *so_sconf_create(apr_pool_t *p, server_rec *s)
eed2a23d9b5986937f1e2b1c120be97744508a72nd soc = (so_server_conf *)apr_pcalloc(p, sizeof(so_server_conf));
eed2a23d9b5986937f1e2b1c120be97744508a72nd soc->loaded_modules = apr_array_make(p, DYNAMIC_MODULE_LIMIT,
eed2a23d9b5986937f1e2b1c120be97744508a72nd return (void *)soc;
eed2a23d9b5986937f1e2b1c120be97744508a72nd * This is the cleanup for a loaded shared object. It unloads the module.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * This is called as a cleanup function from the core.
eed2a23d9b5986937f1e2b1c120be97744508a72nd /* only unload if module information is still existing */
eed2a23d9b5986937f1e2b1c120be97744508a72nd /* remove the module pointer from the core structure */
return APR_SUCCESS;
int retry = 0;
return NULL;
if (retry) {
return NULL;
NULL);
const char *module_file;
const char *error;
&so_module);
modname);
return NULL;
for (i = 0; ap_preloaded_modules[i]; i++) {
const char *preload_name;
* make sure name of preloaded module is mod_FOO.c
NULL);
if (error)
return error;
NULL);
if (error) {
return error;
return NULL;
if (error)
return error;
return NULL;
&so_module);
return NULL;
&so_module);
return NULL;
return NULL;
#ifndef NO_DLOPEN
{ NULL }