4680N/A * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 4680N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4680N/A * This code is free software; you can redistribute it and/or modify it 4680N/A * under the terms of the GNU General Public License version 2 only, as 4680N/A * published by the Free Software Foundation. Oracle designates this 4680N/A * particular file as subject to the "Classpath" exception as provided 4680N/A * by Oracle in the LICENSE file that accompanied this code. 4680N/A * This code is distributed in the hope that it will be useful, but WITHOUT 4680N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4680N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4680N/A * version 2 for more details (a copy is included in the LICENSE file that 4680N/A * You should have received a copy of the GNU General Public License version 4680N/A * 2 along with this work; if not, write to the Free Software Foundation, 4680N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4680N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4680N/A * jexec is used by the system to allow execution of JAR files. 4680N/A * Essentially jexec needs to run java and 4680N/A * needs to be a native ISA executable (not a shell script), although 4680N/A * this native ISA executable requirement was a mistake that will be fixed. 4680N/A * (<ISA> is sparc or i386 or amd64). 4680N/A * When you execute a jar file, jexec is executed by the system as follows: 4680N/A * so this just needs to be turned into: 4680N/A * Solaris systems (new 7's and all 8's) will be looking for jexec at: 4680N/A * and reboot the machine for this to work. 4680N/A * This source should be compiled as: 4680N/A * And jexec should be placed at the following location of the installation: 4680N/A * NOTE: Unless <INSTALLATIONDIR> is the "default" JDK on the system 4680N/A * (i.e. /usr/java -> <INSTALLATIONDIR>), this jexec will not be 4680N/A * found. The 1.2 java is only the default on Solaris 8 and 4680N/A * on systems where the 1.2 packages were installed and no 1.1 4680N/A * NOTE: You must use 1.2 jar to build your jar files. The system 4680N/A * doesn't seem to pick up 1.1 jar files. 4680N/A * NOTE: We don't need to set LD_LIBRARY_PATH here, even though we 4680N/A * are running the actual java binary because the java binary will 4680N/A * look for it's libraries through it's own runpath, which uses 4680N/A * NOTE: This jexec should NOT have any special .so library needs because 4680N/A * it appears that this executable will NOT get the $ORIGIN of jexec 4680N/A * but the $ORIGIN of the jar file being executed. Be careful to keep 4680N/A * this program simple and with no .so dependencies. 4680N/A/* Define a constant that represents the number of directories to pop off the 4680N/A * current location to find the java binary */ 4680N/A/* path to java after popping */ 4680N/A/* flag used when running JAR files */ 4680N/A * This is the main entry point. This program (jexec) will attempt to execute 4680N/A * a JAR file by finding the Java program (java), relative to its own location. 4680N/A * The exact location of the Java program depends on the platform, i.e. 4680N/A * Once the Java program is found, this program copies any remaining arguments 4680N/A * into another array, which is then used to exec the Java program. 4680N/A * On Linux this program does some additional steps. When copying the array of 4680N/A * args, it is necessary to insert the "-jar" flag between arg[0], the program 4680N/A * name, and the original arg[1], which is presumed to be a path to a JAR file. 4680N/A * It is also necessary to verify that the original arg[1] really is a JAR file. 4680N/A * (These steps are unnecessary on Solaris because they are taken care of by 4680N/A /* We need to exec the original arguments using java, instead of jexec. 4680N/A * Also, for Linux, it is necessary to add the "-jar" argument between 4680N/A * the new arg[0], and the old arg[1]. To do this we will create a new 4680N/A /* Make sure we have something to work with */ 4680N/A /* Get the path to the java binary, which is in a known position relative 4680N/A * to our current position, which is in argv[0]. */ 4680N/A /* the next argument is the path to the JAR file */ 4680N/A /* finally copy any remaining arguments */ 4680N/A /* finally add one last terminating null */ 4680N/A /* It's time to exec the java binary with the new arguments. It 4680N/A * is possible that we've reached this point without actually 4680N/A * having a JAR file argument (i.e. if argc < 2), but we still 4680N/A * want to exec the java binary, since that will take care of 4680N/A * displaying the correct usage. */ 4680N/A /* If the exec worked, this process would have been replaced 4680N/A * by the new process. So any code reached beyond this point 4680N/A * implies an error in the exec. */ 4680N/A return 0;
// keep the compiler happy 4680N/A * Exit the application by setting errno, and writing a message. 4680N/A * error - errno is set to this value, and it is used to exit. 4680N/A * message - the message to write. 4680N/A * Get the path to the java binary that should be relative to the current path. 4680N/A * path - the input path that the java binary that should be relative to. 4680N/A * buf - a buffer of size PATH_MAX or greater that the java path is 4680N/A * depth - the number of names to trim off the current path, including the 4680N/A * This function returns 0 on success; otherwise it returns the value of 4680N/A /* Get the full path to this program. Depending on whether this is Solaris 4680N/A * or Linux, this will be something like, 4680N/A /* Pop off the filename, and then subdirectories for each level of 4680N/A /* Append the relative location of java, creating something like, 4680N/A /* Failed to get the path */