author | ksrini |
Mon, 25 Oct 2010 10:34:26 -0700 | |
changeset 7028 | adadd244f506 |
parent 6535 | 77ffd0e75bfb |
child 9244 | 84d85c90d5db |
permissions | -rw-r--r-- |
2 | 1 |
/* |
6005 | 2 |
* Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include "java.h" |
|
27 |
#include <dirent.h> |
|
28 |
#include <dlfcn.h> |
|
29 |
#include <fcntl.h> |
|
30 |
#include <inttypes.h> |
|
31 |
#include <stdio.h> |
|
32 |
#include <string.h> |
|
33 |
#include <stdlib.h> |
|
34 |
#include <sys/stat.h> |
|
35 |
#include <unistd.h> |
|
36 |
#include <sys/types.h> |
|
37 |
#include "manifest_info.h" |
|
38 |
#include "version_comp.h" |
|
39 |
||
40 |
#ifdef __linux__ |
|
41 |
#include <pthread.h> |
|
42 |
#else |
|
43 |
#include <thread.h> |
|
44 |
#endif |
|
45 |
||
46 |
#define JVM_DLL "libjvm.so" |
|
47 |
#define JAVA_DLL "libjava.so" |
|
48 |
||
49 |
/* |
|
50 |
* If a processor / os combination has the ability to run binaries of |
|
51 |
* two data models and cohabitation of jre/jdk bits with both data |
|
52 |
* models is supported, then DUAL_MODE is defined. When DUAL_MODE is |
|
53 |
* defined, the architecture names for the narrow and wide version of |
|
4340
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
54 |
* the architecture are defined in LIBARCH64NAME and LIBARCH32NAME. |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
55 |
* Currently only Solaris on sparc/sparcv9 and i586/amd64 is DUAL_MODE; |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
56 |
* linux i586/amd64 could be defined as DUAL_MODE but that is not the |
2 | 57 |
* current policy. |
58 |
*/ |
|
59 |
||
60 |
#ifdef __solaris__ |
|
61 |
# define DUAL_MODE |
|
62 |
# ifndef LIBARCH32NAME |
|
63 |
# error "The macro LIBARCH32NAME was not defined on the compile line" |
|
64 |
# endif |
|
65 |
# ifndef LIBARCH64NAME |
|
66 |
# error "The macro LIBARCH64NAME was not defined on the compile line" |
|
67 |
# endif |
|
68 |
# include <sys/systeminfo.h> |
|
69 |
# include <sys/elf.h> |
|
70 |
# include <stdio.h> |
|
71 |
#endif |
|
72 |
||
73 |
/* pointer to environment */ |
|
74 |
extern char **environ; |
|
75 |
||
76 |
/* |
|
77 |
* A collection of useful strings. One should think of these as #define |
|
78 |
* entries, but actual strings can be more efficient (with many compilers). |
|
79 |
*/ |
|
80 |
#ifdef __linux__ |
|
81 |
static const char *system_dir = "/usr/java"; |
|
82 |
static const char *user_dir = "/java"; |
|
83 |
#else /* Solaris */ |
|
84 |
static const char *system_dir = "/usr/jdk"; |
|
85 |
static const char *user_dir = "/jdk"; |
|
86 |
#endif |
|
87 |
||
88 |
/* Store the name of the executable once computed */ |
|
89 |
static char *execname = NULL; |
|
90 |
||
91 |
/* |
|
92 |
* Flowchart of launcher execs and options processing on unix |
|
93 |
* |
|
94 |
* The selection of the proper vm shared library to open depends on |
|
95 |
* several classes of command line options, including vm "flavor" |
|
96 |
* options (-client, -server) and the data model options, -d32 and |
|
97 |
* -d64, as well as a version specification which may have come from |
|
98 |
* the command line or from the manifest of an executable jar file. |
|
99 |
* The vm selection options are not passed to the running |
|
100 |
* virtual machine; they must be screened out by the launcher. |
|
101 |
* |
|
102 |
* The version specification (if any) is processed first by the |
|
103 |
* platform independent routine SelectVersion. This may result in |
|
104 |
* the exec of the specified launcher version. |
|
105 |
* |
|
4340
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
106 |
* Previously the launcher modified the LD_LIBRARY_PATH appropriately for the |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
107 |
* desired data model path, regardless if data models matched or not. The |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
108 |
* launcher subsequently exec'ed the desired executable, in order to make the |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
109 |
* LD_LIBRARY_PATH path available for the runtime linker. This is no longer the |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
110 |
* case, the launcher dlopens the target libjvm.so. All other required |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
111 |
* libraries are loaded by the runtime linker, by virtue of the $ORIGIN paths |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
112 |
* baked into the shared libraries, by the build infrastructure at compile time. |
2 | 113 |
* |
4340
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
114 |
* Main |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
115 |
* (incoming argv) |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
116 |
* | |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
117 |
* \|/ |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
118 |
* SelectVersion |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
119 |
* (selects the JRE version, note: not data model) |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
120 |
* | |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
121 |
* \|/ |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
122 |
* CreateExecutionEnvironment |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
123 |
* (determines desired data model) |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
124 |
* | |
2 | 125 |
* | |
126 |
* \|/ |
|
4340
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
127 |
* Have Desired Model ? --> NO --> Is Dual-Mode ? --> NO --> Exit(with error) |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
128 |
* | | |
2 | 129 |
* | | |
4340
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
130 |
* | \|/ |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
131 |
* | YES |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
132 |
* | | |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
133 |
* | | |
2 | 134 |
* | \|/ |
4340
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
135 |
* | CheckJvmType |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
136 |
* | (removes -client, -server etc.) |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
137 |
* | | |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
138 |
* | | |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
139 |
* \|/ \|/ |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
140 |
* YES (find the desired executable and exec child) |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
141 |
* | | |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
142 |
* | | |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
143 |
* \|/ \|/ |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
144 |
* CheckJvmType Main |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
145 |
* (removes -client, -server, etc.) |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
146 |
* | |
2 | 147 |
* | |
148 |
* \|/ |
|
149 |
* TranslateDashJArgs... |
|
150 |
* (Prepare to pass args to vm) |
|
151 |
* | |
|
152 |
* | |
|
153 |
* \|/ |
|
154 |
* ParseArguments |
|
4340
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
155 |
* (removes -d32 and -d64 if any, |
2 | 156 |
* processes version options, |
157 |
* creates argument list for vm, |
|
158 |
* etc.) |
|
159 |
* |
|
160 |
*/ |
|
161 |
||
162 |
static const char * SetExecname(char **argv); |
|
163 |
static jboolean GetJVMPath(const char *jrepath, const char *jvmtype, |
|
164 |
char *jvmpath, jint jvmpathsize, const char * arch); |
|
165 |
static jboolean GetJREPath(char *path, jint pathsize, const char * arch, jboolean speculative); |
|
166 |
||
167 |
||
168 |
#define GetArch() GetArchPath(CURRENT_DATA_MODEL) |
|
169 |
||
170 |
const char * |
|
171 |
GetArchPath(int nbits) |
|
172 |
{ |
|
173 |
switch(nbits) { |
|
174 |
#ifdef DUAL_MODE |
|
175 |
case 32: |
|
176 |
return LIBARCH32NAME; |
|
177 |
case 64: |
|
178 |
return LIBARCH64NAME; |
|
179 |
#endif /* DUAL_MODE */ |
|
180 |
default: |
|
181 |
return LIBARCHNAME; |
|
182 |
} |
|
183 |
} |
|
184 |
||
185 |
void |
|
6005 | 186 |
CreateExecutionEnvironment(int *pargc, char ***pargv, |
187 |
char jrepath[], jint so_jrepath, |
|
188 |
char jvmpath[], jint so_jvmpath) { |
|
2 | 189 |
/* |
190 |
* First, determine if we are running the desired data model. If we |
|
191 |
* are running the desired data model, all the error messages |
|
192 |
* associated with calling GetJREPath, ReadKnownVMs, etc. should be |
|
193 |
* output. However, if we are not running the desired data model, |
|
194 |
* some of the errors should be suppressed since it is more |
|
195 |
* informative to issue an error message based on whether or not the |
|
196 |
* os/processor combination has dual mode capabilities. |
|
197 |
*/ |
|
198 |
||
199 |
jboolean jvmpathExists; |
|
200 |
||
201 |
/* Compute/set the name of the executable */ |
|
6005 | 202 |
SetExecname(*pargv); |
2 | 203 |
|
4340
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
204 |
/* Check data model flags, and exec process, if needed */ |
2 | 205 |
{ |
206 |
char *arch = (char *)GetArch(); /* like sparc or sparcv9 */ |
|
207 |
char * jvmtype = NULL; |
|
6005 | 208 |
int argc = *pargc; |
209 |
char **argv = *pargv; |
|
2 | 210 |
|
211 |
int running = CURRENT_DATA_MODEL; |
|
212 |
||
213 |
int wanted = running; /* What data mode is being |
|
214 |
asked for? Current model is |
|
215 |
fine unless another model |
|
216 |
is asked for */ |
|
217 |
||
218 |
char** newargv = NULL; |
|
219 |
int newargc = 0; |
|
220 |
||
221 |
/* |
|
222 |
* Starting in 1.5, all unix platforms accept the -d32 and -d64 |
|
223 |
* options. On platforms where only one data-model is supported |
|
224 |
* (e.g. ia-64 Linux), using the flag for the other data model is |
|
225 |
* an error and will terminate the program. |
|
226 |
*/ |
|
227 |
||
228 |
{ /* open new scope to declare local variables */ |
|
229 |
int i; |
|
230 |
||
6005 | 231 |
newargv = (char **)JLI_MemAlloc((argc+1) * sizeof(char*)); |
2 | 232 |
newargv[newargc++] = argv[0]; |
233 |
||
234 |
/* scan for data model arguments and remove from argument list; |
|
235 |
last occurrence determines desired data model */ |
|
236 |
for (i=1; i < argc; i++) { |
|
237 |
||
238 |
if (JLI_StrCmp(argv[i], "-J-d64") == 0 || JLI_StrCmp(argv[i], "-d64") == 0) { |
|
239 |
wanted = 64; |
|
240 |
continue; |
|
241 |
} |
|
242 |
if (JLI_StrCmp(argv[i], "-J-d32") == 0 || JLI_StrCmp(argv[i], "-d32") == 0) { |
|
243 |
wanted = 32; |
|
244 |
continue; |
|
245 |
} |
|
246 |
newargv[newargc++] = argv[i]; |
|
247 |
||
248 |
if (IsJavaArgs()) { |
|
249 |
if (argv[i][0] != '-') continue; |
|
250 |
} else { |
|
251 |
if (JLI_StrCmp(argv[i], "-classpath") == 0 || JLI_StrCmp(argv[i], "-cp") == 0) { |
|
252 |
i++; |
|
253 |
if (i >= argc) break; |
|
254 |
newargv[newargc++] = argv[i]; |
|
255 |
continue; |
|
256 |
} |
|
257 |
if (argv[i][0] != '-') { i++; break; } |
|
258 |
} |
|
259 |
} |
|
260 |
||
261 |
/* copy rest of args [i .. argc) */ |
|
262 |
while (i < argc) { |
|
263 |
newargv[newargc++] = argv[i++]; |
|
264 |
} |
|
265 |
newargv[newargc] = NULL; |
|
266 |
||
267 |
/* |
|
268 |
* newargv has all proper arguments here |
|
269 |
*/ |
|
270 |
||
271 |
argc = newargc; |
|
272 |
argv = newargv; |
|
273 |
} |
|
274 |
||
275 |
/* If the data model is not changing, it is an error if the |
|
276 |
jvmpath does not exist */ |
|
277 |
if (wanted == running) { |
|
278 |
/* Find out where the JRE is that we will be using. */ |
|
279 |
if (!GetJREPath(jrepath, so_jrepath, arch, JNI_FALSE) ) { |
|
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
280 |
JLI_ReportErrorMessage(JRE_ERROR1); |
2 | 281 |
exit(2); |
282 |
} |
|
283 |
||
284 |
/* Find the specified JVM type */ |
|
285 |
if (ReadKnownVMs(jrepath, arch, JNI_FALSE) < 1) { |
|
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
286 |
JLI_ReportErrorMessage(CFG_ERROR7); |
2 | 287 |
exit(1); |
288 |
} |
|
289 |
||
290 |
jvmpath[0] = '\0'; |
|
6005 | 291 |
jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE); |
292 |
if (JLI_StrCmp(jvmtype, "ERROR") == 0) { |
|
293 |
JLI_ReportErrorMessage(CFG_ERROR9); |
|
294 |
exit(4); |
|
295 |
} |
|
2 | 296 |
|
297 |
if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch )) { |
|
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
298 |
JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath); |
2 | 299 |
exit(4); |
300 |
} |
|
4340
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
301 |
/* |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
302 |
* we seem to have everything we need, so without further ado |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
303 |
* we return back. |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
304 |
*/ |
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
305 |
return; |
2 | 306 |
} else { /* do the same speculatively or exit */ |
307 |
#ifdef DUAL_MODE |
|
308 |
if (running != wanted) { |
|
309 |
/* Find out where the JRE is that we will be using. */ |
|
310 |
if (!GetJREPath(jrepath, so_jrepath, GetArchPath(wanted), JNI_TRUE)) { |
|
6005 | 311 |
/* give up and let other code report error message */ |
312 |
JLI_ReportErrorMessage(JRE_ERROR2, wanted); |
|
313 |
exit(1); |
|
2 | 314 |
} |
315 |
||
316 |
/* |
|
317 |
* Read in jvm.cfg for target data model and process vm |
|
318 |
* selection options. |
|
319 |
*/ |
|
320 |
if (ReadKnownVMs(jrepath, GetArchPath(wanted), JNI_TRUE) < 1) { |
|
6005 | 321 |
/* give up and let other code report error message */ |
322 |
JLI_ReportErrorMessage(JRE_ERROR2, wanted); |
|
323 |
exit(1); |
|
2 | 324 |
} |
325 |
jvmpath[0] = '\0'; |
|
6005 | 326 |
jvmtype = CheckJvmType(pargc, pargv, JNI_TRUE); |
327 |
if (JLI_StrCmp(jvmtype, "ERROR") == 0) { |
|
328 |
JLI_ReportErrorMessage(CFG_ERROR9); |
|
329 |
exit(4); |
|
330 |
} |
|
331 |
||
2 | 332 |
/* exec child can do error checking on the existence of the path */ |
333 |
jvmpathExists = GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, GetArchPath(wanted)); |
|
334 |
||
335 |
} |
|
336 |
#else |
|
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
337 |
JLI_ReportErrorMessage(JRE_ERROR2, wanted); |
2 | 338 |
exit(1); |
339 |
#endif |
|
340 |
} |
|
341 |
||
342 |
{ |
|
343 |
char *newexec = execname; |
|
344 |
#ifdef DUAL_MODE |
|
345 |
/* |
|
346 |
* If the data model is being changed, the path to the |
|
347 |
* executable must be updated accordingly; the executable name |
|
348 |
* and directory the executable resides in are separate. In the |
|
349 |
* case of 32 => 64, the new bits are assumed to reside in, e.g. |
|
350 |
* "olddir/LIBARCH64NAME/execname"; in the case of 64 => 32, |
|
351 |
* the bits are assumed to be in "olddir/../execname". For example, |
|
352 |
* |
|
353 |
* olddir/sparcv9/execname |
|
354 |
* olddir/amd64/execname |
|
355 |
* |
|
356 |
* for Solaris SPARC and Linux amd64, respectively. |
|
357 |
*/ |
|
358 |
||
359 |
if (running != wanted) { |
|
360 |
char *oldexec = JLI_StrCpy(JLI_MemAlloc(JLI_StrLen(execname) + 1), execname); |
|
361 |
char *olddir = oldexec; |
|
362 |
char *oldbase = JLI_StrRChr(oldexec, '/'); |
|
363 |
||
364 |
||
365 |
newexec = JLI_MemAlloc(JLI_StrLen(execname) + 20); |
|
366 |
*oldbase++ = 0; |
|
367 |
sprintf(newexec, "%s/%s/%s", olddir, |
|
368 |
((wanted==64) ? LIBARCH64NAME : ".."), oldbase); |
|
369 |
argv[0] = newexec; |
|
370 |
} |
|
371 |
#endif |
|
4340
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
372 |
JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n"); |
2 | 373 |
(void)fflush(stdout); |
374 |
(void)fflush(stderr); |
|
4340
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
375 |
execv(newexec, argv); |
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
376 |
JLI_ReportErrorMessageSys(JRE_ERROR4, newexec); |
2 | 377 |
|
378 |
#ifdef DUAL_MODE |
|
379 |
if (running != wanted) { |
|
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
380 |
JLI_ReportErrorMessage(JRE_ERROR5, wanted, running); |
2 | 381 |
# ifdef __solaris__ |
382 |
# ifdef __sparc |
|
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
383 |
JLI_ReportErrorMessage(JRE_ERROR6); |
2 | 384 |
# else |
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
385 |
JLI_ReportErrorMessage(JRE_ERROR7); |
2 | 386 |
# endif |
387 |
} |
|
388 |
# endif |
|
389 |
#endif |
|
390 |
||
391 |
} |
|
392 |
exit(1); |
|
393 |
} |
|
394 |
||
395 |
} |
|
396 |
||
397 |
/* |
|
398 |
* On Solaris VM choosing is done by the launcher (java.c). |
|
399 |
*/ |
|
400 |
static jboolean |
|
401 |
GetJVMPath(const char *jrepath, const char *jvmtype, |
|
402 |
char *jvmpath, jint jvmpathsize, const char * arch) |
|
403 |
{ |
|
404 |
struct stat s; |
|
405 |
||
406 |
if (JLI_StrChr(jvmtype, '/')) { |
|
6005 | 407 |
JLI_Snprintf(jvmpath, jvmpathsize, "%s/" JVM_DLL, jvmtype); |
2 | 408 |
} else { |
6005 | 409 |
JLI_Snprintf(jvmpath, jvmpathsize, "%s/lib/%s/%s/" JVM_DLL, jrepath, arch, jvmtype); |
2 | 410 |
} |
411 |
||
412 |
JLI_TraceLauncher("Does `%s' exist ... ", jvmpath); |
|
413 |
||
414 |
if (stat(jvmpath, &s) == 0) { |
|
415 |
JLI_TraceLauncher("yes.\n"); |
|
416 |
return JNI_TRUE; |
|
417 |
} else { |
|
418 |
JLI_TraceLauncher("no.\n"); |
|
419 |
return JNI_FALSE; |
|
420 |
} |
|
421 |
} |
|
422 |
||
423 |
/* |
|
424 |
* Find path to JRE based on .exe's location or registry settings. |
|
425 |
*/ |
|
426 |
static jboolean |
|
427 |
GetJREPath(char *path, jint pathsize, const char * arch, jboolean speculative) |
|
428 |
{ |
|
429 |
char libjava[MAXPATHLEN]; |
|
430 |
||
431 |
if (GetApplicationHome(path, pathsize)) { |
|
432 |
/* Is JRE co-located with the application? */ |
|
6005 | 433 |
JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/%s/" JAVA_DLL, path, arch); |
2 | 434 |
if (access(libjava, F_OK) == 0) { |
6005 | 435 |
JLI_TraceLauncher("JRE path is %s\n", path); |
436 |
return JNI_TRUE; |
|
2 | 437 |
} |
438 |
||
439 |
/* Does the app ship a private JRE in <apphome>/jre directory? */ |
|
6005 | 440 |
JLI_Snprintf(libjava, sizeof(libjava), "%s/jre/lib/%s/" JAVA_DLL, path, arch); |
2 | 441 |
if (access(libjava, F_OK) == 0) { |
442 |
JLI_StrCat(path, "/jre"); |
|
6005 | 443 |
JLI_TraceLauncher("JRE path is %s\n", path); |
444 |
return JNI_TRUE; |
|
2 | 445 |
} |
446 |
} |
|
447 |
||
448 |
if (!speculative) |
|
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
449 |
JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL); |
2 | 450 |
return JNI_FALSE; |
451 |
} |
|
452 |
||
453 |
jboolean |
|
454 |
LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn) |
|
455 |
{ |
|
456 |
Dl_info dlinfo; |
|
457 |
void *libjvm; |
|
458 |
||
459 |
JLI_TraceLauncher("JVM path is %s\n", jvmpath); |
|
460 |
||
461 |
libjvm = dlopen(jvmpath, RTLD_NOW + RTLD_GLOBAL); |
|
462 |
if (libjvm == NULL) { |
|
463 |
#if defined(__solaris__) && defined(__sparc) && !defined(_LP64) /* i.e. 32-bit sparc */ |
|
464 |
FILE * fp; |
|
465 |
Elf32_Ehdr elf_head; |
|
466 |
int count; |
|
467 |
int location; |
|
468 |
||
469 |
fp = fopen(jvmpath, "r"); |
|
6005 | 470 |
if (fp == NULL) { |
471 |
JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror()); |
|
472 |
return JNI_FALSE; |
|
473 |
} |
|
2 | 474 |
|
475 |
/* read in elf header */ |
|
476 |
count = fread((void*)(&elf_head), sizeof(Elf32_Ehdr), 1, fp); |
|
477 |
fclose(fp); |
|
6005 | 478 |
if (count < 1) { |
479 |
JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror()); |
|
480 |
return JNI_FALSE; |
|
481 |
} |
|
2 | 482 |
|
483 |
/* |
|
484 |
* Check for running a server vm (compiled with -xarch=v8plus) |
|
485 |
* on a stock v8 processor. In this case, the machine type in |
|
486 |
* the elf header would not be included the architecture list |
|
487 |
* provided by the isalist command, which is turn is gotten from |
|
488 |
* sysinfo. This case cannot occur on 64-bit hardware and thus |
|
489 |
* does not have to be checked for in binaries with an LP64 data |
|
490 |
* model. |
|
491 |
*/ |
|
6005 | 492 |
if (elf_head.e_machine == EM_SPARC32PLUS) { |
2 | 493 |
char buf[257]; /* recommended buffer size from sysinfo man |
494 |
page */ |
|
495 |
long length; |
|
496 |
char* location; |
|
497 |
||
498 |
length = sysinfo(SI_ISALIST, buf, 257); |
|
6005 | 499 |
if (length > 0) { |
500 |
location = JLI_StrStr(buf, "sparcv8plus "); |
|
501 |
if (location == NULL) { |
|
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
502 |
JLI_ReportErrorMessage(JVM_ERROR3); |
2 | 503 |
return JNI_FALSE; |
504 |
} |
|
505 |
} |
|
506 |
} |
|
507 |
#endif |
|
6005 | 508 |
JLI_ReportErrorMessage(DLL_ERROR1, __LINE__); |
509 |
JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror()); |
|
510 |
return JNI_FALSE; |
|
2 | 511 |
} |
512 |
||
513 |
ifn->CreateJavaVM = (CreateJavaVM_t) |
|
6005 | 514 |
dlsym(libjvm, "JNI_CreateJavaVM"); |
515 |
if (ifn->CreateJavaVM == NULL) { |
|
516 |
JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror()); |
|
517 |
return JNI_FALSE; |
|
518 |
} |
|
2 | 519 |
|
520 |
ifn->GetDefaultJavaVMInitArgs = (GetDefaultJavaVMInitArgs_t) |
|
521 |
dlsym(libjvm, "JNI_GetDefaultJavaVMInitArgs"); |
|
6005 | 522 |
if (ifn->GetDefaultJavaVMInitArgs == NULL) { |
523 |
JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror()); |
|
524 |
return JNI_FALSE; |
|
525 |
} |
|
2 | 526 |
|
527 |
return JNI_TRUE; |
|
528 |
} |
|
529 |
||
530 |
/* |
|
531 |
* If app is "/foo/bin/javac", or "/foo/bin/sparcv9/javac" then put |
|
532 |
* "/foo" into buf. |
|
533 |
*/ |
|
534 |
jboolean |
|
535 |
GetApplicationHome(char *buf, jint bufsize) |
|
536 |
{ |
|
537 |
if (execname != NULL) { |
|
6535
77ffd0e75bfb
6390477: (launcher) replace unsafe usages of sprintf with snprintf
ksrini
parents:
6005
diff
changeset
|
538 |
JLI_Snprintf(buf, bufsize, "%s", execname); |
2 | 539 |
buf[bufsize-1] = '\0'; |
540 |
} else { |
|
541 |
return JNI_FALSE; |
|
542 |
} |
|
543 |
||
544 |
if (JLI_StrRChr(buf, '/') == 0) { |
|
545 |
buf[0] = '\0'; |
|
546 |
return JNI_FALSE; |
|
547 |
} |
|
548 |
*(JLI_StrRChr(buf, '/')) = '\0'; /* executable file */ |
|
549 |
if (JLI_StrLen(buf) < 4 || JLI_StrRChr(buf, '/') == 0) { |
|
550 |
buf[0] = '\0'; |
|
551 |
return JNI_FALSE; |
|
552 |
} |
|
553 |
if (JLI_StrCmp("/bin", buf + JLI_StrLen(buf) - 4) != 0) |
|
554 |
*(JLI_StrRChr(buf, '/')) = '\0'; /* sparcv9 or amd64 */ |
|
555 |
if (JLI_StrLen(buf) < 4 || JLI_StrCmp("/bin", buf + JLI_StrLen(buf) - 4) != 0) { |
|
556 |
buf[0] = '\0'; |
|
557 |
return JNI_FALSE; |
|
558 |
} |
|
559 |
*(JLI_StrRChr(buf, '/')) = '\0'; /* bin */ |
|
560 |
||
561 |
return JNI_TRUE; |
|
562 |
} |
|
563 |
||
564 |
||
565 |
/* |
|
566 |
* Return true if the named program exists |
|
567 |
*/ |
|
568 |
static int |
|
569 |
ProgramExists(char *name) |
|
570 |
{ |
|
571 |
struct stat sb; |
|
572 |
if (stat(name, &sb) != 0) return 0; |
|
573 |
if (S_ISDIR(sb.st_mode)) return 0; |
|
574 |
return (sb.st_mode & S_IEXEC) != 0; |
|
575 |
} |
|
576 |
||
577 |
||
578 |
/* |
|
579 |
* Find a command in a directory, returning the path. |
|
580 |
*/ |
|
581 |
static char * |
|
582 |
Resolve(char *indir, char *cmd) |
|
583 |
{ |
|
584 |
char name[PATH_MAX + 2], *real; |
|
585 |
||
586 |
if ((JLI_StrLen(indir) + JLI_StrLen(cmd) + 1) > PATH_MAX) return 0; |
|
6005 | 587 |
JLI_Snprintf(name, sizeof(name), "%s%c%s", indir, FILE_SEPARATOR, cmd); |
2 | 588 |
if (!ProgramExists(name)) return 0; |
589 |
real = JLI_MemAlloc(PATH_MAX + 2); |
|
590 |
if (!realpath(name, real)) |
|
591 |
JLI_StrCpy(real, name); |
|
592 |
return real; |
|
593 |
} |
|
594 |
||
595 |
||
596 |
/* |
|
597 |
* Find a path for the executable |
|
598 |
*/ |
|
599 |
static char * |
|
600 |
FindExecName(char *program) |
|
601 |
{ |
|
602 |
char cwdbuf[PATH_MAX+2]; |
|
603 |
char *path; |
|
604 |
char *tmp_path; |
|
605 |
char *f; |
|
606 |
char *result = NULL; |
|
607 |
||
608 |
/* absolute path? */ |
|
609 |
if (*program == FILE_SEPARATOR || |
|
610 |
(FILE_SEPARATOR=='\\' && JLI_StrRChr(program, ':'))) |
|
611 |
return Resolve("", program+1); |
|
612 |
||
613 |
/* relative path? */ |
|
614 |
if (JLI_StrRChr(program, FILE_SEPARATOR) != 0) { |
|
615 |
char buf[PATH_MAX+2]; |
|
616 |
return Resolve(getcwd(cwdbuf, sizeof(cwdbuf)), program); |
|
617 |
} |
|
618 |
||
619 |
/* from search path? */ |
|
620 |
path = getenv("PATH"); |
|
621 |
if (!path || !*path) path = "."; |
|
622 |
tmp_path = JLI_MemAlloc(JLI_StrLen(path) + 2); |
|
623 |
JLI_StrCpy(tmp_path, path); |
|
624 |
||
625 |
for (f=tmp_path; *f && result==0; ) { |
|
626 |
char *s = f; |
|
627 |
while (*f && (*f != PATH_SEPARATOR)) ++f; |
|
628 |
if (*f) *f++ = 0; |
|
629 |
if (*s == FILE_SEPARATOR) |
|
630 |
result = Resolve(s, program); |
|
631 |
else { |
|
632 |
/* relative path element */ |
|
633 |
char dir[2*PATH_MAX]; |
|
6005 | 634 |
JLI_Snprintf(dir, sizeof(dir), "%s%c%s", getcwd(cwdbuf, sizeof(cwdbuf)), |
2 | 635 |
FILE_SEPARATOR, s); |
636 |
result = Resolve(dir, program); |
|
637 |
} |
|
638 |
if (result != 0) break; |
|
639 |
} |
|
640 |
||
641 |
JLI_MemFree(tmp_path); |
|
642 |
return result; |
|
643 |
} |
|
644 |
||
645 |
||
646 |
||
647 |
/* |
|
648 |
* Compute the name of the executable |
|
649 |
* |
|
650 |
* In order to re-exec securely we need the absolute path of the |
|
651 |
* executable. On Solaris getexecname(3c) may not return an absolute |
|
652 |
* path so we use dladdr to get the filename of the executable and |
|
653 |
* then use realpath to derive an absolute path. From Solaris 9 |
|
654 |
* onwards the filename returned in DL_info structure from dladdr is |
|
655 |
* an absolute pathname so technically realpath isn't required. |
|
656 |
* On Linux we read the executable name from /proc/self/exe. |
|
657 |
* As a fallback, and for platforms other than Solaris and Linux, |
|
658 |
* we use FindExecName to compute the executable name. |
|
659 |
*/ |
|
660 |
static const char* |
|
661 |
SetExecname(char **argv) |
|
662 |
{ |
|
663 |
char* exec_path = NULL; |
|
664 |
#if defined(__solaris__) |
|
665 |
{ |
|
666 |
Dl_info dlinfo; |
|
667 |
int (*fptr)(); |
|
668 |
||
669 |
fptr = (int (*)())dlsym(RTLD_DEFAULT, "main"); |
|
670 |
if (fptr == NULL) { |
|
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
671 |
JLI_ReportErrorMessage(DLL_ERROR3, dlerror()); |
2 | 672 |
return JNI_FALSE; |
673 |
} |
|
674 |
||
675 |
if (dladdr((void*)fptr, &dlinfo)) { |
|
676 |
char *resolved = (char*)JLI_MemAlloc(PATH_MAX+1); |
|
677 |
if (resolved != NULL) { |
|
678 |
exec_path = realpath(dlinfo.dli_fname, resolved); |
|
679 |
if (exec_path == NULL) { |
|
680 |
JLI_MemFree(resolved); |
|
681 |
} |
|
682 |
} |
|
683 |
} |
|
684 |
} |
|
685 |
#elif defined(__linux__) |
|
686 |
{ |
|
687 |
const char* self = "/proc/self/exe"; |
|
688 |
char buf[PATH_MAX+1]; |
|
689 |
int len = readlink(self, buf, PATH_MAX); |
|
690 |
if (len >= 0) { |
|
691 |
buf[len] = '\0'; /* readlink doesn't nul terminate */ |
|
692 |
exec_path = JLI_StringDup(buf); |
|
693 |
} |
|
694 |
} |
|
695 |
#else /* !__solaris__ && !__linux */ |
|
696 |
{ |
|
697 |
/* Not implemented */ |
|
698 |
} |
|
699 |
#endif |
|
700 |
||
701 |
if (exec_path == NULL) { |
|
702 |
exec_path = FindExecName(argv[0]); |
|
703 |
} |
|
704 |
execname = exec_path; |
|
705 |
return exec_path; |
|
706 |
} |
|
707 |
||
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
708 |
void JLI_ReportErrorMessage(const char* fmt, ...) { |
2 | 709 |
va_list vl; |
710 |
va_start(vl, fmt); |
|
711 |
vfprintf(stderr, fmt, vl); |
|
712 |
fprintf(stderr, "\n"); |
|
713 |
va_end(vl); |
|
714 |
} |
|
715 |
||
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
716 |
void JLI_ReportErrorMessageSys(const char* fmt, ...) { |
2 | 717 |
va_list vl; |
718 |
char *emsg; |
|
719 |
||
720 |
/* |
|
721 |
* TODO: its safer to use strerror_r but is not available on |
|
722 |
* Solaris 8. Until then.... |
|
723 |
*/ |
|
724 |
emsg = strerror(errno); |
|
725 |
if (emsg != NULL) { |
|
726 |
fprintf(stderr, "%s\n", emsg); |
|
727 |
} |
|
728 |
||
729 |
va_start(vl, fmt); |
|
730 |
vfprintf(stderr, fmt, vl); |
|
731 |
fprintf(stderr, "\n"); |
|
732 |
va_end(vl); |
|
733 |
} |
|
734 |
||
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
735 |
void JLI_ReportExceptionDescription(JNIEnv * env) { |
2 | 736 |
(*env)->ExceptionDescribe(env); |
737 |
} |
|
738 |
||
739 |
/* |
|
740 |
* Since using the file system as a registry is a bit risky, perform |
|
741 |
* additional sanity checks on the identified directory to validate |
|
742 |
* it as a valid jre/sdk. |
|
743 |
* |
|
744 |
* Return 0 if the tests fail; otherwise return non-zero (true). |
|
745 |
* |
|
746 |
* Note that checking for anything more than the existence of an |
|
747 |
* executable object at bin/java relative to the path being checked |
|
748 |
* will break the regression tests. |
|
749 |
*/ |
|
750 |
static int |
|
751 |
CheckSanity(char *path, char *dir) |
|
752 |
{ |
|
753 |
char buffer[PATH_MAX]; |
|
754 |
||
755 |
if (JLI_StrLen(path) + JLI_StrLen(dir) + 11 > PATH_MAX) |
|
756 |
return (0); /* Silently reject "impossibly" long paths */ |
|
757 |
||
6005 | 758 |
JLI_Snprintf(buffer, sizeof(buffer), "%s/%s/bin/java", path, dir); |
2 | 759 |
return ((access(buffer, X_OK) == 0) ? 1 : 0); |
760 |
} |
|
761 |
||
762 |
/* |
|
763 |
* Determine if there is an acceptable JRE in the directory dirname. |
|
764 |
* Upon locating the "best" one, return a fully qualified path to |
|
765 |
* it. "Best" is defined as the most advanced JRE meeting the |
|
766 |
* constraints contained in the manifest_info. If no JRE in this |
|
767 |
* directory meets the constraints, return NULL. |
|
768 |
* |
|
769 |
* Note that we don't check for errors in reading the directory |
|
770 |
* (which would be done by checking errno). This is because it |
|
771 |
* doesn't matter if we get an error reading the directory, or |
|
772 |
* we just don't find anything interesting in the directory. We |
|
773 |
* just return NULL in either case. |
|
774 |
* |
|
775 |
* The historical names of j2sdk and j2re were changed to jdk and |
|
776 |
* jre respecively as part of the 1.5 rebranding effort. Since the |
|
777 |
* former names are legacy on Linux, they must be recognized for |
|
778 |
* all time. Fortunately, this is a minor cost. |
|
779 |
*/ |
|
780 |
static char |
|
781 |
*ProcessDir(manifest_info *info, char *dirname) |
|
782 |
{ |
|
783 |
DIR *dirp; |
|
784 |
struct dirent *dp; |
|
785 |
char *best = NULL; |
|
786 |
int offset; |
|
787 |
int best_offset = 0; |
|
788 |
char *ret_str = NULL; |
|
789 |
char buffer[PATH_MAX]; |
|
790 |
||
791 |
if ((dirp = opendir(dirname)) == NULL) |
|
792 |
return (NULL); |
|
793 |
||
794 |
do { |
|
795 |
if ((dp = readdir(dirp)) != NULL) { |
|
796 |
offset = 0; |
|
797 |
if ((JLI_StrNCmp(dp->d_name, "jre", 3) == 0) || |
|
798 |
(JLI_StrNCmp(dp->d_name, "jdk", 3) == 0)) |
|
799 |
offset = 3; |
|
800 |
else if (JLI_StrNCmp(dp->d_name, "j2re", 4) == 0) |
|
801 |
offset = 4; |
|
802 |
else if (JLI_StrNCmp(dp->d_name, "j2sdk", 5) == 0) |
|
803 |
offset = 5; |
|
804 |
if (offset > 0) { |
|
805 |
if ((JLI_AcceptableRelease(dp->d_name + offset, |
|
806 |
info->jre_version)) && CheckSanity(dirname, dp->d_name)) |
|
807 |
if ((best == NULL) || (JLI_ExactVersionId( |
|
808 |
dp->d_name + offset, best + best_offset) > 0)) { |
|
809 |
if (best != NULL) |
|
810 |
JLI_MemFree(best); |
|
811 |
best = JLI_StringDup(dp->d_name); |
|
812 |
best_offset = offset; |
|
813 |
} |
|
814 |
} |
|
815 |
} |
|
816 |
} while (dp != NULL); |
|
817 |
(void) closedir(dirp); |
|
818 |
if (best == NULL) |
|
819 |
return (NULL); |
|
820 |
else { |
|
821 |
ret_str = JLI_MemAlloc(JLI_StrLen(dirname) + JLI_StrLen(best) + 2); |
|
822 |
sprintf(ret_str, "%s/%s", dirname, best); |
|
823 |
JLI_MemFree(best); |
|
824 |
return (ret_str); |
|
825 |
} |
|
826 |
} |
|
827 |
||
828 |
/* |
|
829 |
* This is the global entry point. It examines the host for the optimal |
|
830 |
* JRE to be used by scanning a set of directories. The set of directories |
|
831 |
* is platform dependent and can be overridden by the environment |
|
832 |
* variable JAVA_VERSION_PATH. |
|
833 |
* |
|
834 |
* This routine itself simply determines the set of appropriate |
|
835 |
* directories before passing control onto ProcessDir(). |
|
836 |
*/ |
|
837 |
char* |
|
838 |
LocateJRE(manifest_info* info) |
|
839 |
{ |
|
840 |
char *path; |
|
841 |
char *home; |
|
842 |
char *target = NULL; |
|
843 |
char *dp; |
|
844 |
char *cp; |
|
845 |
||
846 |
/* |
|
847 |
* Start by getting JAVA_VERSION_PATH |
|
848 |
*/ |
|
849 |
if (info->jre_restrict_search) { |
|
850 |
path = JLI_StringDup(system_dir); |
|
851 |
} else if ((path = getenv("JAVA_VERSION_PATH")) != NULL) { |
|
852 |
path = JLI_StringDup(path); |
|
853 |
} else { |
|
854 |
if ((home = getenv("HOME")) != NULL) { |
|
855 |
path = (char *)JLI_MemAlloc(JLI_StrLen(home) + \ |
|
856 |
JLI_StrLen(system_dir) + JLI_StrLen(user_dir) + 2); |
|
857 |
sprintf(path, "%s%s:%s", home, user_dir, system_dir); |
|
858 |
} else { |
|
859 |
path = JLI_StringDup(system_dir); |
|
860 |
} |
|
861 |
} |
|
862 |
||
863 |
/* |
|
864 |
* Step through each directory on the path. Terminate the scan with |
|
865 |
* the first directory with an acceptable JRE. |
|
866 |
*/ |
|
867 |
cp = dp = path; |
|
868 |
while (dp != NULL) { |
|
869 |
cp = JLI_StrChr(dp, (int)':'); |
|
870 |
if (cp != NULL) |
|
7028
adadd244f506
6989469: (launcher) compiler warnings in jli native code
ksrini
parents:
6535
diff
changeset
|
871 |
*cp = '\0'; |
2 | 872 |
if ((target = ProcessDir(info, dp)) != NULL) |
873 |
break; |
|
874 |
dp = cp; |
|
875 |
if (dp != NULL) |
|
876 |
dp++; |
|
877 |
} |
|
878 |
JLI_MemFree(path); |
|
879 |
return (target); |
|
880 |
} |
|
881 |
||
882 |
/* |
|
883 |
* Given a path to a jre to execute, this routine checks if this process |
|
884 |
* is indeed that jre. If not, it exec's that jre. |
|
885 |
* |
|
886 |
* We want to actually check the paths rather than just the version string |
|
887 |
* built into the executable, so that given version specification (and |
|
888 |
* JAVA_VERSION_PATH) will yield the exact same Java environment, regardless |
|
889 |
* of the version of the arbitrary launcher we start with. |
|
890 |
*/ |
|
891 |
void |
|
892 |
ExecJRE(char *jre, char **argv) |
|
893 |
{ |
|
894 |
char wanted[PATH_MAX]; |
|
895 |
const char* progname = GetProgramName(); |
|
896 |
||
897 |
/* |
|
898 |
* Resolve the real path to the directory containing the selected JRE. |
|
899 |
*/ |
|
900 |
if (realpath(jre, wanted) == NULL) { |
|
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
901 |
JLI_ReportErrorMessage(JRE_ERROR9, jre); |
2 | 902 |
exit(1); |
903 |
} |
|
904 |
||
905 |
/* |
|
906 |
* Resolve the real path to the currently running launcher. |
|
907 |
*/ |
|
908 |
SetExecname(argv); |
|
909 |
if (execname == NULL) { |
|
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
910 |
JLI_ReportErrorMessage(JRE_ERROR10); |
2 | 911 |
exit(1); |
912 |
} |
|
913 |
||
914 |
/* |
|
915 |
* If the path to the selected JRE directory is a match to the initial |
|
916 |
* portion of the path to the currently executing JRE, we have a winner! |
|
917 |
* If so, just return. |
|
918 |
*/ |
|
919 |
if (JLI_StrNCmp(wanted, execname, JLI_StrLen(wanted)) == 0) |
|
920 |
return; /* I am the droid you were looking for */ |
|
921 |
||
922 |
||
923 |
/* |
|
924 |
* This should never happen (because of the selection code in SelectJRE), |
|
925 |
* but check for "impossibly" long path names just because buffer overruns |
|
926 |
* can be so deadly. |
|
927 |
*/ |
|
928 |
if (JLI_StrLen(wanted) + JLI_StrLen(progname) + 6 > PATH_MAX) { |
|
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
929 |
JLI_ReportErrorMessage(JRE_ERROR11); |
2 | 930 |
exit(1); |
931 |
} |
|
932 |
||
933 |
/* |
|
934 |
* Construct the path and exec it. |
|
935 |
*/ |
|
936 |
(void)JLI_StrCat(JLI_StrCat(wanted, "/bin/"), progname); |
|
937 |
argv[0] = JLI_StringDup(progname); |
|
938 |
if (JLI_IsTraceLauncher()) { |
|
939 |
int i; |
|
940 |
printf("ReExec Command: %s (%s)\n", wanted, argv[0]); |
|
941 |
printf("ReExec Args:"); |
|
942 |
for (i = 1; argv[i] != NULL; i++) |
|
943 |
printf(" %s", argv[i]); |
|
944 |
printf("\n"); |
|
945 |
} |
|
4340
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
3834
diff
changeset
|
946 |
JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n"); |
2 | 947 |
(void)fflush(stdout); |
948 |
(void)fflush(stderr); |
|
949 |
execv(wanted, argv); |
|
1145
404b11752c57
6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents:
715
diff
changeset
|
950 |
JLI_ReportErrorMessageSys(JRE_ERROR12, wanted); |
2 | 951 |
exit(1); |
952 |
} |
|
953 |
||
954 |
/* |
|
955 |
* "Borrowed" from Solaris 10 where the unsetenv() function is being added |
|
956 |
* to libc thanks to SUSv3 (Standard Unix Specification, version 3). As |
|
957 |
* such, in the fullness of time this will appear in libc on all relevant |
|
958 |
* Solaris/Linux platforms and maybe even the Windows platform. At that |
|
959 |
* time, this stub can be removed. |
|
960 |
* |
|
961 |
* This implementation removes the environment locking for multithreaded |
|
962 |
* applications. (We don't have access to these mutexes within libc and |
|
963 |
* the launcher isn't multithreaded.) Note that what remains is platform |
|
964 |
* independent, because it only relies on attributes that a POSIX environment |
|
965 |
* defines. |
|
966 |
* |
|
967 |
* Returns 0 on success, -1 on failure. |
|
968 |
* |
|
969 |
* Also removed was the setting of errno. The only value of errno set |
|
970 |
* was EINVAL ("Invalid Argument"). |
|
971 |
*/ |
|
972 |
||
973 |
/* |
|
974 |
* s1(environ) is name=value |
|
975 |
* s2(name) is name(not the form of name=value). |
|
976 |
* if names match, return value of 1, else return 0 |
|
977 |
*/ |
|
978 |
static int |
|
979 |
match_noeq(const char *s1, const char *s2) |
|
980 |
{ |
|
981 |
while (*s1 == *s2++) { |
|
982 |
if (*s1++ == '=') |
|
983 |
return (1); |
|
984 |
} |
|
985 |
if (*s1 == '=' && s2[-1] == '\0') |
|
986 |
return (1); |
|
987 |
return (0); |
|
988 |
} |
|
989 |
||
990 |
/* |
|
991 |
* added for SUSv3 standard |
|
992 |
* |
|
993 |
* Delete entry from environ. |
|
994 |
* Do not free() memory! Other threads may be using it. |
|
995 |
* Keep it around forever. |
|
996 |
*/ |
|
997 |
static int |
|
998 |
borrowed_unsetenv(const char *name) |
|
999 |
{ |
|
1000 |
long idx; /* index into environ */ |
|
1001 |
||
1002 |
if (name == NULL || *name == '\0' || |
|
1003 |
JLI_StrChr(name, '=') != NULL) { |
|
1004 |
return (-1); |
|
1005 |
} |
|
1006 |
||
1007 |
for (idx = 0; environ[idx] != NULL; idx++) { |
|
1008 |
if (match_noeq(environ[idx], name)) |
|
1009 |
break; |
|
1010 |
} |
|
1011 |
if (environ[idx] == NULL) { |
|
1012 |
/* name not found but still a success */ |
|
1013 |
return (0); |
|
1014 |
} |
|
1015 |
/* squeeze up one entry */ |
|
1016 |
do { |
|
1017 |
environ[idx] = environ[idx+1]; |
|
1018 |
} while (environ[++idx] != NULL); |
|
1019 |
||
1020 |
return (0); |
|
1021 |
} |
|
1022 |
/* --- End of "borrowed" code --- */ |
|
1023 |
||
1024 |
/* |
|
1025 |
* Wrapper for unsetenv() function. |
|
1026 |
*/ |
|
1027 |
int |
|
1028 |
UnsetEnv(char *name) |
|
1029 |
{ |
|
1030 |
return(borrowed_unsetenv(name)); |
|
1031 |
} |
|
1032 |
||
1033 |
/* --- Splash Screen shared library support --- */ |
|
1034 |
||
1035 |
static const char* SPLASHSCREEN_SO = "libsplashscreen.so"; |
|
1036 |
||
1037 |
static void* hSplashLib = NULL; |
|
1038 |
||
1039 |
void* SplashProcAddress(const char* name) { |
|
1040 |
if (!hSplashLib) { |
|
1041 |
hSplashLib = dlopen(SPLASHSCREEN_SO, RTLD_LAZY | RTLD_GLOBAL); |
|
1042 |
} |
|
1043 |
if (hSplashLib) { |
|
1044 |
void* sym = dlsym(hSplashLib, name); |
|
1045 |
return sym; |
|
1046 |
} else { |
|
1047 |
return NULL; |
|
1048 |
} |
|
1049 |
} |
|
1050 |
||
1051 |
void SplashFreeLibrary() { |
|
1052 |
if (hSplashLib) { |
|
1053 |
dlclose(hSplashLib); |
|
1054 |
hSplashLib = NULL; |
|
1055 |
} |
|
1056 |
} |
|
1057 |
||
1058 |
const char * |
|
1059 |
jlong_format_specifier() { |
|
1060 |
return "%lld"; |
|
1061 |
} |
|
1062 |
||
1063 |
||
1064 |
||
1065 |
/* |
|
1066 |
* Block current thread and continue execution in a new thread |
|
1067 |
*/ |
|
1068 |
int |
|
1069 |
ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) { |
|
1070 |
int rslt; |
|
1071 |
#ifdef __linux__ |
|
1072 |
pthread_t tid; |
|
1073 |
pthread_attr_t attr; |
|
1074 |
pthread_attr_init(&attr); |
|
1075 |
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); |
|
1076 |
||
1077 |
if (stack_size > 0) { |
|
1078 |
pthread_attr_setstacksize(&attr, stack_size); |
|
1079 |
} |
|
1080 |
||
1081 |
if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) { |
|
1082 |
void * tmp; |
|
1083 |
pthread_join(tid, &tmp); |
|
1084 |
rslt = (int)tmp; |
|
1085 |
} else { |
|
1086 |
/* |
|
1087 |
* Continue execution in current thread if for some reason (e.g. out of |
|
1088 |
* memory/LWP) a new thread can't be created. This will likely fail |
|
1089 |
* later in continuation as JNI_CreateJavaVM needs to create quite a |
|
1090 |
* few new threads, anyway, just give it a try.. |
|
1091 |
*/ |
|
1092 |
rslt = continuation(args); |
|
1093 |
} |
|
1094 |
||
1095 |
pthread_attr_destroy(&attr); |
|
1096 |
#else |
|
1097 |
thread_t tid; |
|
1098 |
long flags = 0; |
|
1099 |
if (thr_create(NULL, stack_size, (void *(*)(void *))continuation, args, flags, &tid) == 0) { |
|
1100 |
void * tmp; |
|
1101 |
thr_join(tid, NULL, &tmp); |
|
1102 |
rslt = (int)tmp; |
|
1103 |
} else { |
|
1104 |
/* See above. Continue in current thread if thr_create() failed */ |
|
1105 |
rslt = continuation(args); |
|
1106 |
} |
|
1107 |
#endif |
|
1108 |
return rslt; |
|
1109 |
} |
|
1110 |
||
1111 |
/* Coarse estimation of number of digits assuming the worst case is a 64-bit pid. */ |
|
1112 |
#define MAX_PID_STR_SZ 20 |
|
1113 |
||
1114 |
void SetJavaLauncherPlatformProps() { |
|
1115 |
/* Linux only */ |
|
1116 |
#ifdef __linux__ |
|
1117 |
const char *substr = "-Dsun.java.launcher.pid="; |
|
1118 |
char *pid_prop_str = (char *)JLI_MemAlloc(JLI_StrLen(substr) + MAX_PID_STR_SZ + 1); |
|
1119 |
sprintf(pid_prop_str, "%s%d", substr, getpid()); |
|
1120 |
AddOption(pid_prop_str, NULL); |
|
1121 |
#endif |
|
1122 |
} |
|
1123 |
||
1124 |
jboolean |
|
1125 |
IsJavaw() |
|
1126 |
{ |
|
1127 |
/* noop on UNIX */ |
|
1128 |
return JNI_FALSE; |
|
1129 |
} |
|
39
560da37936db
6596475: (launcher) javaw should call InitCommonControls
ksrini
parents:
2
diff
changeset
|
1130 |
|
560da37936db
6596475: (launcher) javaw should call InitCommonControls
ksrini
parents:
2
diff
changeset
|
1131 |
void |
560da37936db
6596475: (launcher) javaw should call InitCommonControls
ksrini
parents:
2
diff
changeset
|
1132 |
InitLauncher(jboolean javaw) |
560da37936db
6596475: (launcher) javaw should call InitCommonControls
ksrini
parents:
2
diff
changeset
|
1133 |
{ |
560da37936db
6596475: (launcher) javaw should call InitCommonControls
ksrini
parents:
2
diff
changeset
|
1134 |
JLI_SetTraceLauncher(); |
560da37936db
6596475: (launcher) javaw should call InitCommonControls
ksrini
parents:
2
diff
changeset
|
1135 |
} |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1136 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1137 |
/* |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1138 |
* The implementation for finding classes from the bootstrap |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1139 |
* class loader, refer to java.h |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1140 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1141 |
static FindClassFromBootLoader_t *findBootClass = NULL; |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1142 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1143 |
jclass |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1144 |
FindBootStrapClass(JNIEnv *env, const char* classname) |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1145 |
{ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1146 |
if (findBootClass == NULL) { |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1147 |
findBootClass = (FindClassFromBootLoader_t *)dlsym(RTLD_DEFAULT, |
3834
16342ebd576d
6864028: Update the java launcher to use the new entry point JVM_FindClassFromBootLoader
mchung
parents:
1331
diff
changeset
|
1148 |
"JVM_FindClassFromBootLoader"); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1149 |
if (findBootClass == NULL) { |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1150 |
JLI_ReportErrorMessage(DLL_ERROR4, |
3834
16342ebd576d
6864028: Update the java launcher to use the new entry point JVM_FindClassFromBootLoader
mchung
parents:
1331
diff
changeset
|
1151 |
"JVM_FindClassFromBootLoader"); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1152 |
return NULL; |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1153 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1154 |
} |
3834
16342ebd576d
6864028: Update the java launcher to use the new entry point JVM_FindClassFromBootLoader
mchung
parents:
1331
diff
changeset
|
1155 |
return findBootClass(env, classname); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
1145
diff
changeset
|
1156 |
} |