[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-java
Subject:    [patch] daemonctl.c modified to use JAVA_HOME environment variable
From:       Brent Verner <brent () rcfile ! org>
Date:       2003-02-07 16:32:17
[Download RAW message or body]

The attached patch modified the daemonctl.c program to use JAVA_HOME
if set in the environment.

cheers.
  brent

-- 
"Develop your talent, man, and leave the world something. Records are 
really gifts from people. To think that an artist would love you enough
to share his music with anyone is a beautiful thing."  -- Duane Allman

["daemonctl.c.diff" (text/plain)]

--- ports/www/jakarta-tomcat4/files/daemonctl.c	Fri Feb  7 06:44:18 2003
+++ ports/www/jakarta-tomcat4/files/daemonctl.c.new	Fri Feb  7 06:39:18 2003
@@ -20,6 +20,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/uio.h>
+#include <limits.h>
 
 /* The maximum size of the PID file, in bytes */
 #define MAX_FILE_SIZE			32
@@ -56,6 +57,9 @@
 private void stop(void);
 private void restart(void);
 
+private char java_home[PATH_MAX] = "%%JAVA_HOME%%"; /* default: "%%JAVA_HOME%%" */
+private char java_prog[PATH_MAX] = "%%JAVA_HOME%%/%%JAVA_CMD%%"; /* default: \
"%%JAVA_HOME%%/%%JAVA_CMD%%" */ +private int  using_java_home_env = 0;
 
 /**
  * Main function. This function is called when this program is executed.
@@ -71,7 +75,16 @@
 
 	/* Declare variables, like all other good ANSI C programs do :) */
 	char *argument;
-
+    
+    /* use JAVA_HOME environemt variable if set */
+    char* _java_home = getenv("JAVA_HOME");
+    if( _java_home != NULL && strcmp("",_java_home) != 0 ){
+      /* TODO: verify that java_prog would exist before overriding the default */
+      strncpy(java_home,_java_home,PATH_MAX-1);
+      snprintf(java_prog,PATH_MAX-1,"%s/%%JAVA_CMD%%",_java_home);
+      using_java_home_env = 1;
+    }
+    
 	/* Parse the arguments */
 	if (argc < 2) {
 		printUsage();
@@ -82,6 +95,9 @@
 	setuid(geteuid());
 	setgid(getegid());
 
+    if( using_java_home_env )
+        printf(">> using JAVA_HOME environment variable (%s)\n",java_home);
+    
 	argument = argv[1];
 	if (strcmp("start", argument) == 0) {
 		start();
@@ -332,36 +348,36 @@
 	}
 
 	/* Check if the JDK home directory is actually a directory */
-	result = stat("%%JAVA_HOME%%", &sb);
+	result = stat(java_home, &sb);
 	if (result != 0) {
 		printf(" [ FAILED ]\n");
-		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to stat %%JAVA_HOME%%: ");
+		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to stat %s: ",java_home);
 		perror(NULL);
 		exit(ERR_STAT_JAVA_HOME);
 	}
 	if (!S_ISDIR(sb.st_mode)) {
 		printf(" [ FAILED ]\n");
-		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Java home directory %%JAVA_HOME%% is not \
a directory.\n"); +		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Java home directory %s \
is not a directory.\n",java_home);  exit(ERR_JAVA_HOME_NOT_DIR);
 	}
 
 	/* Check if the Java command is actually an executable regular file */
-	result = stat("%%JAVA_HOME%%/%%JAVA_CMD%%", &sb);
+	result = stat(java_prog, &sb);
 	if (result != 0) {
 		printf(" [ FAILED ]\n");
-		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to stat \
%%JAVA_HOME%%/%%JAVA_CMD%%: "); +		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable \
to stat %s: ",java_prog);  perror(NULL);
 		exit(ERR_STAT_JAVA_CMD);
 	}
 	if (!S_ISREG(sb.st_mode)) {
 		printf(" [ FAILED ]\n");
-		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Java command %%JAVA_HOME%%/%%JAVA_CMD%% \
is not a regular file.\n"); +		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Java command \
%s is not a regular file.\n",java_prog);  exit(ERR_JAVA_CMD_NOT_FILE);
 	}
-	result = access("%%JAVA_HOME%%/%%JAVA_CMD%%", X_OK);
+	result = access(java_prog, X_OK);
 	if (result != 0) {
 		printf(" [ FAILED ]\n");
-		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Java command %%JAVA_HOME%%/%%JAVA_CMD%% \
is not executable: "); +		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Java command %s \
is not executable: ",java_prog);  perror(NULL);
 		exit(ERR_JAVA_CMD_NOT_EXECUTABLE);
 	}
@@ -425,9 +441,9 @@
 		         file using pipe(2) */
 
 		/* Execute the command */
-		execl("%%JAVA_HOME%%/%%JAVA_CMD%%", "%%JAVA_HOME%%/%%JAVA_CMD%%", "-jar", \
                %%JAVA_ARGS%% "%%JAR_FILE%%", %%JAR_ARGS%% NULL);
-
-		fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to start %%APP_TITLE%% \
%%PORTVERSION%% since '%%JAVA_HOME%%/%%JAVA_CMD%% -jar %%JAR_FILE%%' in %%APP_HOME%%: \
"); +		execl(java_prog, java_prog, "-jar", %%JAVA_ARGS%% "%%JAR_FILE%%", %%JAR_ARGS%% \
NULL); +		
+        fprintf(stderr, "%%CONTROL_SCRIPT_NAME%%: Unable to start %%APP_TITLE%% \
%%PORTVERSION%% since '%s -jar %%JAR_FILE%%' in %%APP_HOME%%: ",java_prog);  \
perror(NULL);  } else {
 		printf(" [ DONE ]\n");


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-java" in the body of the message

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic