commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ryan M. Graham" <r...@ELOQUENT-SYSTEMS.com>
Subject [PATCH] daemon: pass arbitrary number of parameters through procrun
Date Mon, 08 Mar 2004 18:51:24 GMT
When upgrading to tomcat5 from tomcat4, I noticed the service handling changed and broke some
useful things like passing parameters to tomcat when running as a service. Specifically, it
lost the ability to override the configuration files, with "-config server.xml", for example.

I reworked the command syntax a bit to expand on the --StartupClass argument. It now works
with an arbitrary number of parameters to pass to the method:

--StartupClass package.Class;method;param0;param1;param2;...;paramN
instead of:
--StartupClass package.Class;method;param

ie.
--StartupClass org.apache.catalina.startup.Bootstrap;main;-config;..\custom\server.xml;start

To do this I had to make a couple changes to procrun.h (expanding the java_t struct) and,
of course, converting the parameter handling code to something a little more loop based.

I tried to stick with the existing conventions, please don't beat me if I missed something!


~Ryan

patch below:


Index: procrun.c
===================================================================
RCS file: /home/cvspublic/jakarta-commons/daemon/src/native/nt/procrun/procrun.c,v
retrieving revision 1.14
diff -u -r1.14 procrun.c
--- procrun.c	11 Feb 2004 06:52:24 -0000	1.14
+++ procrun.c	8 Mar 2004 18:34:29 -0000
@@ -565,6 +565,7 @@
  */
 static void debug_process(int argc, char **argv, process_t *p)
 {
+    int i;
     DBPRINTF1("DUMPING %s\n", argv[0]);
     DBPRINTF0("  SERVICE:\n");
     DBPRINTF1("    name        : %s\n", p->service.name);
@@ -581,8 +582,10 @@
     DBPRINTF1("    stop        : %s\n", p->java.stop_class);
     DBPRINTF1("    start method: %s\n", p->java.start_method);
     DBPRINTF1("    stop method : %s\n", p->java.stop_method);
-    DBPRINTF1("    start param : %s\n", p->java.start_param);
-    DBPRINTF1("    stop param  : %s\n", p->java.stop_param);
+	for (i = 0; i < p->java.start_param_count; i++)
+		DBPRINTF2("    start param %d : %s\n", i, p->java.start_param[i]);
+	for (i = 0; i < p->java.stop_param_count; i++)
+		DBPRINTF2("    stop param %d  : %s\n", i, p->java.stop_param[i]);
 
     DBPRINTF0("DONE...\n");
 }
@@ -848,7 +851,9 @@
     char skey[256];
     char kval[MAX_PATH];
     unsigned long klen;
+	int param_count;
     DWORD err;
+	char *px;
     
     if (!proc->service.name)
         return 0;
@@ -916,15 +921,36 @@
             p = strchr(kval, ';');
             if (p) *p = '\0';
             proc->java.start_class = pool_strdup(proc->pool, kval);
+			DBPRINTF1("read start_class: %s\n", kval);
+			if (p) {
+				p++;
+				px = p;
+				if (p = strchr(p, ';'))	{
+					*p = '\0';
+					p++;
+				}
+                proc->java.start_method = pool_strdup(proc->pool, px);
+				DBPRINTF1("read start_method: %s\n", px);
+			}
             if (p) {
-                ++p;
-                proc->java.start_method = pool_strdup(proc->pool, p);
-                p = strchr(proc->java.start_method, ';');
-                if (p) {
-                    *p = '\0';
-                    ++p;
-                    proc->java.start_param = pool_strdup(proc->pool, p);
-                }
+				DBPRINTF1("reading parameters from: %s\n", p);
+				px = p;
+				param_count = 0;
+				while ( p && *p ) {
+					px = strchr(p, ';');
+					if (px) {
+						//there are more parameters to come
+						*px = '\0';
+						px++;
+						DBPRINTF1("there are more parameters in: %s\n", px);
+					}
+					proc->java.start_param[param_count] = pool_strdup(proc->pool, p);
+					DBPRINTF2("read parameter %d: %s\n", param_count, p);
+					param_count++;
+					/* param_count is 0 base, start_param_count is not */
+					proc->java.start_param_count = param_count;
+					p = px;
+				}
             }
         }
         klen = MAX_PATH;
@@ -935,15 +961,36 @@
             p = strchr(kval, ';');
             if (p) *p = '\0';
             proc->java.stop_class = pool_strdup(proc->pool, kval);
+			DBPRINTF1("read stop_class: %s\n", kval);
+			if (p) {
+				p++;
+				px = p;
+				if (p = strchr(p, ';')) {
+					*p = '\0';
+					p++;
+				}
+                proc->java.stop_method = pool_strdup(proc->pool, px);
+				DBPRINTF1("read stop_method: %s\n", px);
+			}
             if (p) {
-                ++p;
-                proc->java.stop_method = pool_strdup(proc->pool, p);
-                p = strchr(proc->java.stop_method, ';');
-                if (p) {
-                    *p = '\0';
-                    ++p;
-                    proc->java.stop_param = pool_strdup(proc->pool, p);
-                }
+				DBPRINTF1("reading parameters from: %s\n", p);
+				px = p;
+				param_count = 0;
+				while ( p && *p ) {
+					px = strchr(p, ';');
+					if (px) {
+						//there are more parameters to come
+						*px = '\0';
+						px++;
+						DBPRINTF1("there are more parameters in: %s\n", px);
+					}
+					proc->java.stop_param[param_count] = pool_strdup(proc->pool, p);
+					DBPRINTF2("read parameter %d: %s\n", param_count, p);
+					param_count++;
+					/* param_count is 0 base, stop_param_count is not */
+					proc->java.stop_param_count = param_count;
+					p = px;
+				}
             }
         }
         klen = MAX_PATH;
@@ -1231,6 +1278,7 @@
     JavaVM *jvm = proc->java.jvm;
     int err;
     JNIEnv *env;
+	jstring arg_i;
 
     DBPRINTF2("procrun_destroy_jvm dll %08x jvm %08x\n",proc->java.dll,proc->java.jvm);
     if (!proc->java.dll || !jvm) {
@@ -1260,10 +1308,16 @@
         DBPRINTF1("Calling shutdown %s\n", proc->java.stop_class); 
 
         strclass = (*env)->FindClass(env, "java/lang/String");
-        if (proc->java.stop_param) {
-            jstring arg = (*env)->NewStringUTF(env, proc->java.stop_param);
-            jargs = (*env)->NewObjectArray(env, 1, strclass, NULL);
-            (*env)->SetObjectArrayElement(env, jargs, 0, arg);
+        if (proc->java.stop_param_count) {
+			/* Add each parameter to the array */
+			int i;
+			jargs = (*env)->NewObjectArray(env, proc->java.stop_param_count, strclass, NULL);
+			for (i = 0; i < proc->java.stop_param_count; i++) {
+				DBPRINTF2("adding stop parameter %d: %s\n", i, proc->java.stop_param[i]);
+				arg_i = (*env)->NewStringUTF(env, proc->java.stop_param[i]);
+				(*env)->SetObjectArrayElement(env, jargs, i, arg_i);
+			}
+
         }
         (*env)->CallStaticVoidMethod(env,
                                      proc->java.stop_bridge,
@@ -1312,6 +1366,7 @@
     char *cp;
     char *opts[32];
     int optn, i, err;
+	jstring arg_i;
 
     vm_args11.version = JNI_VERSION_1_2;
      
@@ -1403,10 +1458,15 @@
         return 0;
     } 
     strclass = (*env)->FindClass(env, "java/lang/String");
-    if (proc->java.start_param) {
-        jstring arg = (*env)->NewStringUTF(env, proc->java.start_param);
-        jargs = (*env)->NewObjectArray(env, 1, strclass, NULL);
-        (*env)->SetObjectArrayElement(env, jargs, 0, arg);
+    if (proc->java.start_param_count) {
+		/* Add each parameter to the array */
+		int i;
+		jargs = (*env)->NewObjectArray(env, proc->java.start_param_count, strclass, NULL);
+		for (i = 0; i < proc->java.start_param_count; i++) {
+			DBPRINTF2("adding start parameter %d: %s\n", i, proc->java.start_param[i]);
+			arg_i = (*env)->NewStringUTF(env, proc->java.start_param[i]);
+			(*env)->SetObjectArrayElement(env, jargs, i, arg_i);
+		}
     }
     (*env)->CallStaticVoidMethod(env,
                                  proc->java.start_bridge,
@@ -1673,7 +1733,8 @@
         int i, j, len = strlen(env->m->argw) + 8192;
         char *opts[64], *nargw;
         char *javaClass = starting ? env->m->java.start_class : env->m->java.stop_class,
-            *javaParam = starting ? env->m->java.start_param : env->m->java.stop_param;
+            **javaParam = starting ? env->m->java.start_param : env->m->java.stop_param;
+		int javaParam_count = starting ? env->m->java.start_param_count : env->m->java.stop_param_count;
 
         j = make_array(env->m->java.opts, opts, 60, env->m);
 
@@ -1700,10 +1761,10 @@
             strcat(nargw, program);
         strcat(nargw, " ");
         strcat(nargw, javaClass);
-        if (javaParam) {
-            strcat(nargw, " ");
-            strcat(nargw, javaParam);
-        }
+		for (i = 0; i < javaParam_count; i++) {
+			strcat(nargw, " ");
+			strcat(nargw, javaParam[i]);
+		}
         env->m->argw = nargw;
         program = env->m->java.jbin;
     return program;
Index: procrun.h
===================================================================
RCS file: /home/cvspublic/jakarta-commons/daemon/src/native/nt/procrun/procrun.h,v
retrieving revision 1.7
diff -u -r1.7 procrun.h
--- procrun.h	11 Feb 2004 05:11:48 -0000	1.7
+++ procrun.h	8 Mar 2004 18:34:29 -0000
@@ -269,8 +269,10 @@
         jmethodID    stop_mid; 
         char         *start_method;
         char         *stop_method;
-        char         *start_param;
-        char         *stop_param;
+        char         *start_param[MAX_PATH];
+        char         *stop_param[MAX_PATH];
+		int          start_param_count;
+		int          stop_param_count;
         char         *opts;
         char         *display;
     };

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message