java_md_common.c revision 5270
1879N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 1472N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A * Return true if the named program exists 0N/A * Find a command in a directory, returning the path. 0N/A * Find a path for the executable 0N/A /* absolute path? */ 0N/A /* relative path? */ 0N/A /* from search path? */ 0N/A /* relative path element */ 0N/A * TODO: its safer to use strerror_r but is not available on 0N/A * Solaris 8. Until then.... 0N/A * Since using the file system as a registry is a bit risky, perform 0N/A * additional sanity checks on the identified directory to validate 0N/A * Return 0 if the tests fail; otherwise return non-zero (true). 0N/A * Note that checking for anything more than the existence of an 0N/A * executable object at bin/java relative to the path being checked 0N/A * will break the regression tests. 0N/A return (0);
/* Silently reject "impossibly" long paths */ 2453N/A * Determine if there is an acceptable JRE in the directory dirname. 0N/A * Upon locating the "best" one, return a fully qualified path to 0N/A * it. "Best" is defined as the most advanced JRE meeting the 0N/A * constraints contained in the manifest_info. If no JRE in this 0N/A * directory meets the constraints, return NULL. 0N/A * Note that we don't check for errors in reading the directory 0N/A * (which would be done by checking errno). This is because it 0N/A * doesn't matter if we get an error reading the directory, or 0N/A * we just don't find anything interesting in the directory. We 0N/A * just return NULL in either case. 0N/A * The historical names of j2sdk and j2re were changed to jdk and 0N/A * jre respecively as part of the 1.5 rebranding effort. Since the 0N/A * former names are legacy on Linux, they must be recognized for 0N/A * all time. Fortunately, this is a minor cost. 1089N/A * This is the global entry point. It examines the host for the optimal 1089N/A * JRE to be used by scanning a set of directories. The set of directories 1089N/A * is platform dependent and can be overridden by the environment 1089N/A * variable JAVA_VERSION_PATH. 1089N/A * This routine itself simply determines the set of appropriate 1089N/A * directories before passing control onto ProcessDir(). * Start by getting JAVA_VERSION_PATH * Step through each directory on the path. Terminate the scan with * the first directory with an acceptable JRE. * Given a path to a jre to execute, this routine checks if this process * is indeed that jre. If not, it exec's that jre. * We want to actually check the paths rather than just the version string * built into the executable, so that given version specification (and * JAVA_VERSION_PATH) will yield the exact same Java environment, regardless * of the version of the arbitrary launcher we start with. * Resolve the real path to the directory containing the selected JRE. * Resolve the real path to the currently running launcher. * If the path to the selected JRE directory is a match to the initial * portion of the path to the currently executing JRE, we have a winner! return;
/* I am the droid you were looking for */ * This should never happen (because of the selection code in SelectJRE), * but check for "impossibly" long path names just because buffer overruns * Construct the path and exec it. * "Borrowed" from Solaris 10 where the unsetenv() function is being added * to libc thanks to SUSv3 (Standard Unix Specification, version 3). As * such, in the fullness of time this will appear in libc on all relevant * Solaris/Linux platforms and maybe even the Windows platform. At that * time, this stub can be removed. * This implementation removes the environment locking for multithreaded * applications. (We don't have access to these mutexes within libc and * the launcher isn't multithreaded.) Note that what remains is platform * independent, because it only relies on attributes that a POSIX environment * Returns 0 on success, -1 on failure. * Also removed was the setting of errno. The only value of errno set * was EINVAL ("Invalid Argument"). * s1(environ) is name=value * s2(name) is name(not the form of name=value). * if names match, return value of 1, else return 0 if (*
s1 ==
'=' &&
s2[-
1] ==
'\0')
* added for SUSv3 standard * Delete entry from environ. * Do not free() memory! Other threads may be using it. * Keep it around forever. long idx;
/* index into environ */ /* name not found but still a success */ /* squeeze up one entry */ /* --- End of "borrowed" code --- */ * Wrapper for unsetenv() function. * The implementation for finding classes from the bootstrap * class loader, refer to java.h "JVM_FindClassFromBootLoader");
"JVM_FindClassFromBootLoader");