From owner-freebsd-java Fri Feb 7 21: 3: 6 2003 Delivered-To: freebsd-java@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1BA6537B401 for ; Fri, 7 Feb 2003 21:03:02 -0800 (PST) Received: from habanero.hesketh.net (habanero.hesketh.net [66.45.6.196]) by mx1.FreeBSD.org (Postfix) with ESMTP id 42A4643FAF for ; Fri, 7 Feb 2003 21:03:01 -0800 (PST) (envelope-from brent@mutt.rcfile.org) Received: from mutt.rcfile.org (rdu57-229-060.nc.rr.com [66.57.229.60]) by habanero.hesketh.net (8.12.6/8.12.6) with ESMTP id h1852pfx012615; Sat, 8 Feb 2003 00:02:53 -0500 X-Received-From: brent@mutt.rcfile.org X-Delivered-To: freebsd-java@FreeBSD.ORG X-Spam-Filter: check_local@habanero.hesketh.net by digitalanswers.org Received: from mutt.rcfile.org (localhost [127.0.0.1]) by mutt.rcfile.org (8.12.6/8.12.6) with ESMTP id h18536XD006762; Sat, 8 Feb 2003 00:03:06 -0500 (EST) (envelope-from brent@mutt.rcfile.org) Received: (from brent@localhost) by mutt.rcfile.org (8.12.6/8.12.6/Submit) id h18536Gf006761; Sat, 8 Feb 2003 00:03:06 -0500 (EST) Date: Sat, 8 Feb 2003 00:03:06 -0500 From: Brent Verner To: k.j.koster@telecom.tno.nl Cc: freebsd-java@FreeBSD.ORG Subject: Re: [patch] daemonctl.c modified to use JAVA_HOME environment variable Message-ID: <20030208050306.GA6480@rcfile.org> References: <0DD8055E0FECF744B5FF8053F80C4A2D194F69@l07.oase.research.kpn.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Kj7319i9nmIyA2yE" Content-Disposition: inline In-Reply-To: <0DD8055E0FECF744B5FF8053F80C4A2D194F69@l07.oase.research.kpn.com> X-muttrc: $Id: .muttrc,v 1.9 2002/01/02 07:04:49 brent Exp $ X-uname: FreeBSD 4.7-STABLE #32: Tue Feb 4 11:04:18 EST 2003 root@mutt.rcfile.org:/usr/obj/usr/src/sys/MUTTS User-Agent: Mutt/1.5.3i Sender: owner-freebsd-java@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline [2003-02-08 03:20] k.j.koster@telecom.tno.nl said: | Dear Brent, | | I would prefer daemonctl to fail if the JAVA_HOME is pointing off | into lala land. I really dislike solutions that are helpfully | filling in information. If I set JAVA_HOME to something odd, I | expect my programs to fail. Please consider this. Point taken. Attached patch causes failure before stop() or start() if env JAVA_HOME doesn't contain a java program. 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 --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="daemonctl.c.diff.1" --- ports/www/jakarta-tomcat4/files/daemonctl.c.orig Fri Feb 7 18:19:35 2003 +++ ports/www/jakarta-tomcat4/files/daemonctl.c Fri Feb 7 23:00:15 2003 @@ -20,6 +20,7 @@ #include #include #include +#include /* The maximum size of the PID file, in bytes */ #define MAX_FILE_SIZE 32 @@ -45,6 +46,7 @@ #define ERR_STAT_JAVA_CMD 14 #define ERR_JAVA_CMD_NOT_FILE 15 #define ERR_JAVA_CMD_NOT_EXECUTABLE 16 +#define ERR_INVALID_JAVA_HOME 18 #define private static @@ -55,7 +57,13 @@ private void start(void); private void stop(void); private void restart(void); +private void setup_java_prog(void); +#define C_JAVA_HOME "%%JAVA_HOME%%" +#define C_JAVA_PROG "%%JAVA_HOME%%/%%JAVA_CMD%%" +private int using_java_home_env = 0; +private char java_home[PATH_MAX] = C_JAVA_HOME; +private char java_prog[PATH_MAX] = C_JAVA_PROG; /** * Main function. This function is called when this program is executed. @@ -78,6 +86,8 @@ return 0; } + setup_java_prog(); /* check for and use JAVA_HOME env */ + /* XXX: Fix for setting up the environment for the java wrapper script */ setuid(geteuid()); setgid(getegid()); @@ -332,36 +342,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 +435,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"); @@ -482,3 +492,44 @@ stop(); start(); } + +/* + * setup java_home and java_prog. If JAVA_HOME is defined in the + * environemt, try to use it. If JAVA_HOME does contain bin/java, + * do not use it. + */ +private void setup_java_prog(void){ + char* _java_home; + + /* use JAVA_HOME environemt variable if set */ + _java_home = getenv("JAVA_HOME"); + if( _java_home != NULL && strcmp("",_java_home) != 0 ){ + char _java_prog[PATH_MAX]; + struct stat st; + int rv; + strlcpy(_java_prog,_java_home,PATH_MAX); + strlcat(_java_prog,"/",PATH_MAX); + strlcat(_java_prog,"%%JAVA_CMD%%",PATH_MAX); + rv = stat(_java_prog,&st); + + /* make sure _java_prog can be used */ + if( rv == 0 + && S_ISREG(st.st_mode) + && ! access(_java_prog, X_OK) ) + { + strlcpy(java_home,_java_home,PATH_MAX); + strlcpy(java_prog,_java_prog,PATH_MAX); + using_java_home_env = 1; + printf("[info] using JAVA_HOME environment variable (%s)\n",java_home); + printf("[info] starting tomcat with %s\n",java_prog); + + } + else + { + fprintf(stderr,"[ FAILED ]\n"); + fprintf(stderr,"%%CONTROL_SCRIPT_NAME%%: invalid JAVA_HOME; %s not found\n",_java_prog); + exit(ERR_INVALID_JAVA_HOME); + } + } +} + --Kj7319i9nmIyA2yE-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-java" in the body of the message