httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r424798 - /httpd/httpd/trunk/modules/database/mod_dbd.c
Date Sun, 23 Jul 2006 20:22:57 GMT
Author: niq
Date: Sun Jul 23 13:22:57 2006
New Revision: 424798

URL: http://svn.apache.org/viewvc?rev=424798&view=rev
Log:
Remove dependence on server config from ap_dbd_prepare, as that may
be called in per-directory config functions where there is no
server context causing segfault.
Discussion at
http://mail-archives.apache.org/mod_mbox/httpd-dev/200607.mbox/<831327593.20060720023332%40engec.ru>
and subsequent thread.

Modified:
    httpd/httpd/trunk/modules/database/mod_dbd.c

Modified: httpd/httpd/trunk/modules/database/mod_dbd.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/database/mod_dbd.c?rev=424798&r1=424797&r2=424798&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/database/mod_dbd.c (original)
+++ httpd/httpd/trunk/modules/database/mod_dbd.c Sun Jul 23 13:22:57 2006
@@ -67,6 +67,8 @@
                cmd_min, cmd_keep, cmd_max, cmd_exp
 } cmd_parts;
 
+static apr_hash_t *dbd_prepared_defns;
+
 /* a default DBDriver value that'll generate meaningful error messages */
 static const char *const no_dbdriver = "[DBDriver unset]";
 
@@ -144,12 +146,13 @@
 DBD_DECLARE_NONSTD(void) ap_dbd_prepare(server_rec *s, const char *query,
                                         const char *label)
 {
-    svr_cfg *svr = ap_get_module_config(s->module_config, &dbd_module);
     dbd_prepared *prepared = apr_pcalloc(s->process->pool, sizeof(dbd_prepared));
     prepared->label = label;
     prepared->query = query;
-    prepared->next = svr->prepared;
-    svr->prepared = prepared;
+    prepared->next = apr_hash_get(dbd_prepared_defns, s->server_hostname,
+                                  APR_HASH_KEY_STRING);
+    apr_hash_set(dbd_prepared_defns, s->server_hostname, APR_HASH_KEY_STRING,
+                 prepared);
 }
 static const char *dbd_prepare(cmd_parms *cmd, void *cfg, const char *query,
                                const char *label)
@@ -299,8 +302,10 @@
     *db = rec;
     rv = dbd_prepared_init(rec->pool, svr, rec);
     if (rv != APR_SUCCESS) {
+        const char *errmsg = apr_dbd_error(rec->driver, rec->handle, rv);
         ap_log_perror(APLOG_MARK, APLOG_CRIT, rv, rec->pool,
-                      "DBD: failed to initialise prepared SQL statements");
+                      "DBD: failed to initialise prepared SQL statements: %s",
+                      (errmsg ? errmsg : "[???]"));
     }
     return rv;
 }
@@ -602,6 +607,23 @@
 }
 #endif
 
+static int dbd_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
+{
+   dbd_prepared_defns = apr_hash_make(ptemp);
+   return OK;
+}
+static int dbd_post_config(apr_pool_t *pconf, apr_pool_t *plog,
+                           apr_pool_t *ptemp, server_rec *s)
+{
+    svr_cfg *svr;
+    server_rec *sp;
+    for (sp = s; sp; sp = sp->next) {
+        svr = ap_get_module_config(sp->module_config, &dbd_module);
+        svr->prepared = apr_hash_get(dbd_prepared_defns, sp->server_hostname,
+                                     APR_HASH_KEY_STRING);
+    }
+    return OK;
+}
 static void dbd_hooks(apr_pool_t *pool)
 {
 #if APR_HAS_THREADS
@@ -613,6 +635,8 @@
     APR_REGISTER_OPTIONAL_FN(ap_dbd_cacquire);
     APR_REGISTER_OPTIONAL_FN(ap_dbd_prepare);
     apr_dbd_init(pool);
+    ap_hook_pre_config(dbd_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
+    ap_hook_post_config(dbd_post_config, NULL, NULL, APR_HOOK_MIDDLE);
 }
 
 module AP_MODULE_DECLARE_DATA dbd_module = {



Mime
View raw message