Date: Fri, 7 Feb 2003 11:32:17 -0500 From: Brent Verner <brent@rcfile.org> To: freebsd-java@freebsd.org Subject: [patch] daemonctl.c modified to use JAVA_HOME environment variable Message-ID: <20030207163217.GA99329@rcfile.org>
next in thread | raw e-mail | index | archive | help
--cWoXeonUoKmBZSoM Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --cWoXeonUoKmBZSoM Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="daemonctl.c.diff" --- 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"); --cWoXeonUoKmBZSoM-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-java" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030207163217.GA99329>