[Mono-devel-list] [PATCH] MonoSetEnv for mod_mono

jreed joel.reed at ddiworld.com
Thu Mar 10 12:57:58 EST 2005


Apache has SetEnv, mod_perl has PerlSetEnv, but I can find no
equivalent for mod_mono.

The attached patch provides for a MonoSetEnv directive
that takes a semicolon-separated list of name=value pairs
which are SETENV'd before forking mod-mono-server. 

I considered changing mod-mono-server instead of mod_mono.c, 
but know of no way to SET environment variables in C# code.

This patch helps portability of .Net web applications
where environment variables are used on Windows/IIS,
while also matching capability found in Apache, mod_perl, etc.

Please consider for inclusion. Its a relatively 
small set of changes. Thanks!

(%:~/src/lm-4.0)- diffstat ~/MonoSetEnv.patch
 mod_mono.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+)

jr
-------------- next part --------------
diff -up -ur mod_mono-1.0.6-orig/src/mod_mono.c mod_mono-1.0.6/src/mod_mono.c
--- mod_mono-1.0.6-orig/src/mod_mono.c	2005-02-06 00:36:44.000000000 -0500
+++ mod_mono-1.0.6/src/mod_mono.c	2005-03-09 15:31:51.000000000 -0500
@@ -51,6 +51,7 @@ typedef struct {
 	char *max_cpu_time;
 	char *max_memory;
 	char *debug;
+	char *environment_variables;
 } mono_server_rec;
 
 /* */
@@ -69,6 +70,7 @@ CONFIG_FUNCTION (listen_address, listen_
 CONFIG_FUNCTION (max_cpu_time, max_cpu_time)
 CONFIG_FUNCTION (max_memory, max_memory)
 CONFIG_FUNCTION (debug, debug)
+CONFIG_FUNCTION (environment_variables, environment_variables)
 
 static void *
 create_mono_server_config (apr_pool_t *p, server_rec *s)
@@ -93,6 +95,7 @@ create_mono_server_config (apr_pool_t *p
 	server->max_cpu_time = NULL;
 	server->max_memory = NULL;
 	server->debug = "False";
+	server->environment_variables = NULL;
 
 	return server;
 }
@@ -614,6 +617,33 @@ setenv_to_putenv (apr_pool_t *pool, char
 #endif
 
 static void
+set_environment_variables (apr_pool_t *pool, char *environment_variables)
+{
+  char *tmp;
+  char *name;
+  char *value;
+
+  /* were any environment_variables specified? */
+  if (environment_variables == NULL) return;
+
+  name = environment_variables;
+  tmp = strchr(environment_variables, '=');
+  while (tmp != NULL)
+    {
+      *tmp = '\0';
+      value = tmp+1;
+      tmp = strchr(value, ';');
+      if (tmp != NULL) *tmp = '\0';
+
+      SETENV(pool, name, value);
+      if (tmp == NULL) break;
+
+      name = tmp+1;
+      tmp = strchr(name, '=');
+    }
+}
+
+static void
 set_process_limits (int max_cpu_time, int max_memory)
 {
 #ifdef HAVE_SETRLIMIT
@@ -700,6 +730,8 @@ fork_mod_mono_server (apr_pool_t *pool, 
 	if (server_conf->max_cpu_time != NULL)
 		max_cpu_time = atoi (server_conf->max_cpu_time);
 
+	set_environment_variables(pool, server_conf->environment_variables);
+
 	pid = fork ();
 	if (pid > 0) {
 		wait (&status);
@@ -1238,6 +1270,11 @@ MAKE_CMD (MonoDebug, debug,
 	"If MonoDebug is true, mono will be run in debug mode."
 	" Default value: False"
 	),
+MAKE_CMD (MonoSetEnv, environment_variables,
+	"A string of name=value pairs separated by semicolons."
+	"For each pair, setenv(name, value) is called."
+	" Default value: Default: \"\""
+	),
 	{ NULL }
 };
 


More information about the Mono-devel-list mailing list