From: Stefan Fritsch Date: Mon, 19 Jul 2010 10:06:15 +0000 (+0000) Subject: Add ap_find_module_short_name() to quickly get the module short name X-Git-Tag: 2.3.7~80 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae5ef058acd8fad2b9d84491338fd032097f05c9;p=thirdparty%2Fapache%2Fhttpd.git Add ap_find_module_short_name() to quickly get the module short name (i.e. symbol name with trailing "_module" removed) from the module_index. To be used for logging. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@965408 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 76491c5da49..2f285a2db63 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -238,12 +238,14 @@ * 20100714.0 (2.3.7-dev) add access_checker_ex hook, add AUTHZ_DENIED_NO_USER * to authz_status, call authz providers twice to allow * authz without authenticated user + * 20100719.0 (2.3.7-dev) Add symbol name parameter to ap_add_module and + * ap_add_loaded_module. Add ap_find_module_short_name */ #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */ #ifndef MODULE_MAGIC_NUMBER_MAJOR -#define MODULE_MAGIC_NUMBER_MAJOR 20100714 +#define MODULE_MAGIC_NUMBER_MAJOR 20100719 #endif #define MODULE_MAGIC_NUMBER_MINOR 0 /* 0...n */ diff --git a/include/http_config.h b/include/http_config.h index 63dd52441b6..27cff77a8ab 100644 --- a/include/http_config.h +++ b/include/http_config.h @@ -671,8 +671,10 @@ AP_DECLARE(char *) ap_server_root_relative(apr_pool_t *p, const char *fname); * Add a module to the server * @param m The module structure of the module to add * @param p The pool of the same lifetime as the module + * @param s The module's symbol name (used for logging) */ -AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p); +AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p, + const char *s); /** * Remove a module from the server. There are some caveats: @@ -687,8 +689,10 @@ AP_DECLARE(void) ap_remove_module(module *m); * Add a module to the chained modules list and the list of loaded modules * @param mod The module structure of the module to add * @param p The pool with the same lifetime as the module + * @param s The module's symbol name (used for logging) */ -AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p); +AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p, + const char *s); /** * Remove a module fromthe chained modules list and the list of loaded modules * @param mod the module structure of the module to remove @@ -700,6 +704,12 @@ AP_DECLARE(void) ap_remove_loaded_module(module *mod); * @return the name of the module */ AP_DECLARE(const char *) ap_find_module_name(module *m); +/** + * Find the short name of the module identified by the specified module index + * @param module_index The module index to get the name for + * @return the name of the module + */ +AP_DECLARE(const char *) ap_find_module_short_name(int module_index); /** * Find a module based on the name of the module * @param name the name of the module diff --git a/modules/core/mod_so.c b/modules/core/mod_so.c index 81eb2366bf8..7be9c0619eb 100644 --- a/modules/core/mod_so.c +++ b/modules/core/mod_so.c @@ -278,7 +278,7 @@ static const char *load_module(cmd_parms *cmd, void *dummy, /* * Add this module to the Apache core structures */ - error = ap_add_loaded_module(modp, cmd->pool); + error = ap_add_loaded_module(modp, cmd->pool, modname); if (error) { return error; } diff --git a/server/config.c b/server/config.c index 07f8f256c89..5f0ae48cdf1 100644 --- a/server/config.c +++ b/server/config.c @@ -202,6 +202,9 @@ AP_DECLARE_DATA module **ap_loaded_modules=NULL; static apr_hash_t *ap_config_hash = NULL; +/* a list of the module symbol names with the trailing "_module"removed */ +static char **ap_module_short_names = NULL; + typedef int (*handler_func)(request_rec *); typedef void *(*dir_maker_func)(apr_pool_t *, char *); typedef void *(*merger_func)(apr_pool_t *, void *, void *); @@ -520,8 +523,11 @@ static void ap_add_module_commands(module *m, apr_pool_t *p) /* One-time setup for precompiled modules --- NOT to be done on restart */ -AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p) +AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p, + const char *sym_name) { + ap_module_symbol_t *sym = ap_prelinked_module_symbols; + /* This could be called from a LoadModule httpd.conf command, * after the file has been linked and the module structure within it * teased out... @@ -549,8 +555,30 @@ AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p) "reached. Please increase " "DYNAMIC_MODULE_LIMIT and recompile.", m->name); } + + } + else if (!sym_name) { + while (sym->modp != NULL) { + if (sym->modp == m) { + sym_name = sym->name; + break; + } + sym++; + } } + if (sym_name) { + int len = strlen(sym_name); + int slen = strlen("_module"); + if (len > slen && !strcmp(sym_name + len - slen, "_module")) { + len -= slen; + } + + ap_module_short_names[m->module_index] = strdup(sym_name); + ap_module_short_names[m->module_index][len] = '\0'; + } + + /* Some C compilers put a complete path into __FILE__, but we want * only the filename (e.g. mod_includes.c). So check for path * components (Unix and DOS), and remove them. @@ -623,13 +651,17 @@ AP_DECLARE(void) ap_remove_module(module *m) modp->next = modp->next->next; } + free(ap_module_short_names[m->module_index]); + ap_module_short_names[m->module_index] = NULL; + m->module_index = -1; /* simulate being unloaded, should * be unnecessary */ dynamic_modules--; total_modules--; } -AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p) +AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p, + const char *short_name) { module **m; const char *error; @@ -637,7 +669,7 @@ AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p) /* * Add module pointer to top of chained module list */ - error = ap_add_module(mod, p); + error = ap_add_module(mod, p, short_name); if (error) { return error; } @@ -709,12 +741,14 @@ AP_DECLARE(const char *) ap_setup_prelinked_modules(process_rec *process) conf_vector_length = max_modules; /* - * Initialise list of loaded modules + * Initialise list of loaded modules and short names */ ap_loaded_modules = (module **)apr_palloc(process->pool, sizeof(module *) * conf_vector_length); + if (!ap_module_short_names) + ap_module_short_names = malloc(sizeof(char *) * conf_vector_length); - if (ap_loaded_modules == NULL) { + if (ap_loaded_modules == NULL || ap_module_short_names == NULL) { return "Ouch! Out of memory in ap_setup_prelinked_modules()!"; } @@ -727,7 +761,7 @@ AP_DECLARE(const char *) ap_setup_prelinked_modules(process_rec *process) * Initialize chain of linked (=activate) modules */ for (m = ap_prelinked_modules; *m != NULL; m++) { - error = ap_add_module(*m, process->pconf); + error = ap_add_module(*m, process->pconf, NULL); if (error) { return error; } @@ -743,6 +777,13 @@ AP_DECLARE(const char *) ap_find_module_name(module *m) return m->name; } +AP_DECLARE(const char *) ap_find_module_short_name(int module_index) +{ + if (module_index < 0) + return "-"; + return ap_module_short_names[module_index]; +} + AP_DECLARE(module *) ap_find_linked_module(const char *name) { module *modp;