You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by sc...@apache.org on 2006/12/30 03:40:07 UTC

svn commit: r491153 - /httpd/httpd/trunk/modules/experimental/mod_example.c

Author: sctemme
Date: Fri Dec 29 18:40:07 2006
New Revision: 491153

URL: http://svn.apache.org/viewvc?view=rev&rev=491153
Log:

Ongoing crusade to separate callback tracing into single-process
single-thread part and thread-safe per-request or per-connection
(forthcoming) routines.  Implement trace_startup() routine and call it
from startup hook handlers instead of the old trace_add routine.  This
completely separates the global variable manipulation from the
request-specific stuff.  Otherwise, it's mostly existing code.

Modified:
    httpd/httpd/trunk/modules/experimental/mod_example.c

Modified: httpd/httpd/trunk/modules/experimental/mod_example.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/experimental/mod_example.c?view=diff&rev=491153&r1=491152&r2=491153
==============================================================================
--- httpd/httpd/trunk/modules/experimental/mod_example.c (original)
+++ httpd/httpd/trunk/modules/experimental/mod_example.c Fri Dec 29 18:40:07 2006
@@ -467,6 +467,50 @@
     }
 }
 
+/* 
+ * This utility routine traces the hooks called when the server starts up. 
+ * It leaves a trace in a global variable, so it should not be called from 
+ * a hook handler that runs in a multi-threaded situation. 
+ */
+
+static void trace_startup(apr_pool_t *p, server_rec *s, x_cfg *mconfig, 
+                          const char *note)
+{
+    const char *sofar;
+    char *where, *addon;
+
+#ifdef EXAMPLE_LOG_EACH 
+    example_log_each(p, s, note);
+#endif
+
+    /*
+     * If we weren't passed a configuration record, we can't figure out to
+     * what location this call applies.  This only happens for co-routines
+     * that don't operate in a particular directory or server context.  If we
+     * got a valid record, extract the location (directory or server) to which
+     * it applies.
+     */
+    where = (mconfig != NULL) ? mconfig->loc : "nowhere";
+    where = (where != NULL) ? where : "";
+
+    addon = apr_pstrcat(p,
+                        "   <li>\n"
+                        "    <dl>\n"
+                        "     <dt><samp>", note, "</samp></dt>\n"
+                        "     <dd><samp>[", where, "]</samp></dd>\n"
+                        "    </dl>\n"
+                        "   </li>\n",
+                        NULL);
+
+    /* 
+     * Make sure that we start with a valid string, even if we have never been 
+     * called.  
+     */
+    sofar = (trace == NULL) ? "" : trace;
+    
+    trace = apr_pstrcat(p, sofar, addon, NULL);
+}
+
 
 /*
  * This utility route traces the hooks called as a request is handled. 
@@ -536,7 +580,7 @@
      * "Example Wuz Here"
      */
     cfg->local = 1;
-    trace_add(cmd->server, NULL, cfg, "cmd_example()");
+    trace_startup(cmd->pool, cmd->server, cfg, "cmd_example()");
     return NULL;
 }
 
@@ -574,8 +618,9 @@
      */
     dname = (dname != NULL) ? dname : "";
     cfg->loc = apr_pstrcat(p, "DIR(", dname, ")", NULL);
-    note = apr_psprintf(p, "x_create_dir_config(p == 0x%x, dirspec == %s)", p, dirspec);
-    trace_add(NULL, NULL, cfg, note);
+    note = apr_psprintf(p, "x_create_dir_config(p == 0x%x, dirspec == %s)", 
+                        p, dirspec);
+    trace_startup(p, NULL, cfg, note);
     return (void *) cfg;
 }
 
@@ -629,7 +674,7 @@
     note = apr_psprintf(p, "x_merge_dir_config(p == 0x%x, parent_conf == " 
                         "0x%x, newloc_conf == 0x%x)", p, parent_conf,
                         newloc_conf);
-    trace_add(NULL, NULL, merged_config, note);
+    trace_startup(p, NULL, merged_config, note);
     return (void *) merged_config;
 }
 
@@ -659,7 +704,7 @@
      */
     sname = (sname != NULL) ? sname : "";
     cfg->loc = apr_pstrcat(p, "SVR(", sname, ")", NULL);
-    trace_add(s, NULL, cfg, "x_create_server_config()");
+    trace_startup(p, s, cfg, "x_create_server_config()");
     return (void *) cfg;
 }
 
@@ -699,7 +744,7 @@
      */
     note = apr_pstrcat(p, "x_merge_server_config(\"", s1conf->loc, "\",\"",
                    s2conf->loc, "\")", NULL);
-    trace_add(NULL, NULL, merged_config, note);
+    trace_startup(p, NULL, merged_config, note);
     return (void *) merged_config;
 }
 
@@ -749,7 +794,7 @@
     /*
      * Log the call and exit.
      */
-    trace_add(NULL, NULL, NULL, "x_pre_config()");
+    trace_startup(ptemp, NULL, NULL, "x_pre_config()");
 
     return OK;
 }
@@ -771,7 +816,7 @@
     /*
      * Log the call and exit.
      */
-    trace_add(s, NULL, NULL, "x_check_config()");
+    trace_startup(ptemp, s, NULL, "x_check_config()");
     return OK;
 }
 
@@ -791,7 +836,7 @@
 
     apr_file_printf(out, "Example module configuration test routine\n");
     
-    trace_add(s, NULL, NULL, "x_test_config()");
+    trace_startup(pconf, s, NULL, "x_test_config()");
 }
 
 /*
@@ -808,7 +853,7 @@
     /*
      * Log the call and exit.
      */
-    trace_add(s, NULL, NULL, "x_open_logs()");
+    trace_startup(ptemp, s, NULL, "x_open_logs()");
     return OK;
 }
 
@@ -828,7 +873,7 @@
     /*
      * Log the call and exit.
      */
-    trace_add(s, NULL, NULL, "x_post_config()");
+    trace_startup(ptemp, s, NULL, "x_post_config()");
     return OK;
 }
 
@@ -847,7 +892,7 @@
      */
     sname = (sname != NULL) ? sname : "";
     note = apr_pstrcat(s->process->pool, "x_child_exit(", sname, ")", NULL);
-    trace_add(s, NULL, NULL, note);
+    trace_startup(s->process->pool, s, NULL, note);
     return APR_SUCCESS;
 }
 
@@ -871,7 +916,7 @@
      */
     sname = (sname != NULL) ? sname : "";
     note = apr_pstrcat(p, "x_child_init(", sname, ")", NULL);
-    trace_add(s, NULL, NULL, note);
+    trace_startup(p, s, NULL, note);
 
     apr_pool_cleanup_register(p, s, x_child_exit, x_child_exit);
 }