Graham Dumpleton wrote:
Grisha wrote ..

On Tue, 14 Feb 2006, Jim Gallacher wrote:


I wonder if we should generalize this, so rather than PythonMutexDir,

we have
PythonModuleConfig. Usage might look like:

PythonModuleConfig mutex_dir /path/to/mutexs
PythonModuleConfig max_mutex_locks 8

I may be wrong, but I think the reason this was never configurable was
because the mutex is created before the apache config is read.


Correct, is actually done from the mod_python module init function.

The only way one could have it dynamically changing is through an
Apache -D option checked by using ap_exists_config_define().

This is incorrect. You can get at the directives from python_init. Proof of concept patch attached. Apply the patch and add the following directives in your apache config after the LoadModule.

LoadModule python_module /usr/lib/apache2/modules/mod_python.so
PythonModuleConfig max_locks 911
PythonModuleConfig mutex_dir /some/place/safe

Check the error.log for the results.

I'm sure I don't need to tell everyone that this is intend as Proof of Concept only. Don't blame me if your hair catches on fire and your teeth fall out as a result of using this patch. :)

Jim
Index: src/mod_python.c
===================================================================
--- src/mod_python.c    (revision 377430)
+++ src/mod_python.c    (working copy)
@@ -314,7 +314,25 @@
     int max_clients;
     int locks;
     int n;
+    
 
+    /* PythonModuleConfig Proof of Concept */
+    char *val;
+    py_config *conf =
+        (py_config *) ap_get_module_config(s->module_config, 
+                                           &python_module);
+    ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
+                 "TEST init_mutexes: checking for values set by 
PythonModuleConfig");
+
+    val = apr_table_get(conf->directives, "max_locks");
+    ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
+                 "TEST init_mutexes: max_locks = %s", val);
+
+    val = apr_table_get(conf->directives, "mutex_dir");
+    ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
+                 "TEST init_mutexes: mutex_dir = %s", val);
+    /* end POC */
+
     /* figre out maximum possible concurrent connections */
     /* MAX_DAEMON_USED seems to account for MaxClients, as opposed to
        MAX_DAEMONS, which is ServerLimit
@@ -1621,7 +1639,45 @@
     return NULL;
 }
 
+
 /**
+ ** directive_PythonModuleConfig
+ **
+ *      This function called whenever PythonModuleConfig directive
+ *      is encountered.
+ *
+ *      WARNING WARNING WARNING
+ *      This is proof of concept code
+ *      DO NOT USE IN PRODUCTION
+ */
+static const char *directive_PythonModuleConfig(cmd_parms *cmd, void * 
mconfig, 
+                                          const char *key, const char *val)
+{
+    py_config *conf;
+    conf = (py_config *) mconfig;
+    if(val!=NULL) {
+        apr_table_set(conf->options, key, val);
+
+        conf = ap_get_module_config(cmd->server->module_config,
+                                    &python_module);
+        apr_table_set(conf->directives, key, val);
+    }
+    else {
+       /** We don't remove the value, but set it
+           to an empty string. There is no possibility
+           of colliding with an actual value, since
+           an entry string precisely means 'remove the value' */
+        apr_table_set(conf->directives, key, "");
+
+        conf = ap_get_module_config(cmd->server->module_config,
+                                    &python_module);
+        apr_table_set(conf->directives, key, "");
+    }
+    return NULL;
+}
+
+
+/**
  ** directive_PythonOptimize
  **
  *      This function called whenever PythonOptimize directive
@@ -2131,6 +2187,9 @@
     AP_INIT_TAKE12(
         "PythonOutputFilter", directive_PythonOutputFilter, NULL, 
RSRC_CONF|ACCESS_CONF,
         "Python output filter."),
+    AP_INIT_TAKE12(
+        "PythonModuleConfig", directive_PythonModuleConfig, NULL, RSRC_CONF,
+        "Python module configuration."),
     {NULL}
 };
 

Reply via email to