jdk/src/solaris/bin/java_md.c
author ngmr
Mon, 10 Oct 2011 14:50:51 +0100
changeset 10706 9bd5de10aaf9
parent 9244 84d85c90d5db
child 12291 1be435e23542
permissions -rw-r--r--
7099119: Remove unused dlinfo local variable in launcher code Reviewed-by: ohair, chegar, ngmr Contributed-by: Steve Poole <spoole@linux.vnet.ibm.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
     2
 * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4340
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4340
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4340
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4340
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4340
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "java.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <dirent.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <dlfcn.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <fcntl.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <inttypes.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <sys/stat.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <unistd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "manifest_info.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include "version_comp.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include <pthread.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include <thread.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#define JVM_DLL "libjvm.so"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#define JAVA_DLL "libjava.so"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
    49
/* help jettison the LD_LIBRARY_PATH settings in the future */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
    50
#ifndef SETENV_REQUIRED
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
    51
#define SETENV_REQUIRED
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
    52
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * If a processor / os combination has the ability to run binaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * two data models and cohabitation of jre/jdk bits with both data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * models is supported, then DUAL_MODE is defined.  When DUAL_MODE is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * 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
    58
 * the architecture are defined in LIBARCH64NAME and LIBARCH32NAME.
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
    59
 * 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
    60
 * linux i586/amd64 could be defined as DUAL_MODE but that is not the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * current policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#ifdef __solaris__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#  define DUAL_MODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#  ifndef LIBARCH32NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#    error "The macro LIBARCH32NAME was not defined on the compile line"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#  endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#  ifndef LIBARCH64NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#    error "The macro LIBARCH64NAME was not defined on the compile line"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#  endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
#  include <sys/systeminfo.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
#  include <sys/elf.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
#  include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
/* pointer to environment */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
extern char **environ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *      A collection of useful strings. One should think of these as #define
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *      entries, but actual strings can be more efficient (with many compilers).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
static const char *system_dir   = "/usr/java";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
static const char *user_dir     = "/java";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
#else /* Solaris */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
static const char *system_dir   = "/usr/jdk";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
static const char *user_dir     = "/jdk";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
/* Store the name of the executable once computed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
static char *execname = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * Flowchart of launcher execs and options processing on unix
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * The selection of the proper vm shared library to open depends on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * several classes of command line options, including vm "flavor"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * options (-client, -server) and the data model options, -d32  and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * -d64, as well as a version specification which may have come from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * the command line or from the manifest of an executable jar file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * The vm selection options are not passed to the running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * virtual machine; they must be screened out by the launcher.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * The version specification (if any) is processed first by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * platform independent routine SelectVersion.  This may result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * the exec of the specified launcher version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   110
 * 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
   111
 * 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
   112
 * launcher subsequently exec'ed the desired executable, in order to make the
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   113
 * LD_LIBRARY_PATH path available, for the runtime linker.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   114
 *
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   115
 * Now, in most cases,the launcher will dlopen the target libjvm.so. All
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   116
 * required libraries are loaded by the runtime linker, using the
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   117
 * $RPATH/$ORIGIN baked into the shared libraries at compile time. Therefore,
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   118
 * in most cases, the launcher will only exec, if the data models are
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   119
 * mismatched, and will not set any environment variables, regardless of the
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   120
 * data models.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   121
 *
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   122
 * However, if the environment contains a LD_LIBRARY_PATH, this will cause the
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   123
 * launcher to inspect the LD_LIBRARY_PATH. The launcher will check
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   124
 *  a. if the LD_LIBRARY_PATH's first component is the the path to the desired
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   125
 *     libjvm.so
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   126
 *  b. if any other libjvm.so is found in any of the paths.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   127
 * If case b is true, then the launcher will set the LD_LIBRARY_PATH to the
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   128
 * desired JRE and reexec, in order to propagate the environment.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   130
 *  Main
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   131
 *  (incoming argv)
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
 * \|/
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   134
 * SelectVersion
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   135
 * (selects the JRE version, note: not data model)
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   136
 *  |
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
 * CreateExecutionEnvironment
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   139
 * (determines desired data model)
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   140
 *  |
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 *  |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * \|/
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   143
 *  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
   144
 *  |                                          |
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *  |                                          |
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   146
 *  |                                         \|/
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   147
 *  |                                         YES
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   148
 *  |                                          |
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   149
 *  |                                          |
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *  |                                         \|/
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   151
 *  |                                CheckJvmType
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   152
 *  |                               (removes -client, -server etc.)
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   153
 *  |                                          |
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   154
 *  |                                          |
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   155
 * \|/                                        \|/
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   156
 * YES                             Find the desired executable/library
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   157
 *  |                                          |
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   158
 *  |                                          |
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   159
 * \|/                                        \|/
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   160
 * CheckJvmType                          RequiresSetenv
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   161
 * (removes -client, -server, etc.)
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   162
 *  |
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *  |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * \|/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * TranslateDashJArgs...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * (Prepare to pass args to vm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 *  |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *  |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * \|/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * ParseArguments
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   171
 * (removes -d32 and -d64 if any,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 *  processes version options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 *  creates argument list for vm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 *  etc.)
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   175
 *   |
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   176
 *   |
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   177
 *  \|/
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   178
 * RequiresSetenv
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   179
 * Is LD_LIBRARY_PATH
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   180
 * and friends set ? --> NO --> Have Desired Model ? NO --> Re-exec --> Main
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   181
 *  YES                              YES --> Continue
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   182
 *   |
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   183
 *   |
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   184
 *  \|/
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   185
 * Path is desired JRE ? YES --> Have Desired Model ? NO --> Re-exec --> Main
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   186
 *  NO                               YES --> Continue
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   187
 *   |
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   188
 *   |
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   189
 *  \|/
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   190
 * Paths have well known
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   191
 * jvm paths ?       --> NO --> Have Desired Model ? NO --> Re-exec --> Main
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   192
 *  YES                              YES --> Continue
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   193
 *   |
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   194
 *   |
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   195
 *  \|/
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   196
 *  Does libjvm.so exit
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   197
 *  in any of them ? --> NO --> Have Desired Model ? NO --> Re-exec --> Main
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   198
 *   YES                             YES --> Continue
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   199
 *   |
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   200
 *   |
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   201
 *  \|/
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   202
 *  Set the LD_LIBRARY_PATH
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   203
 *   |
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   204
 *   |
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   205
 *  \|/
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   206
 * Re-exec
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   207
 *   |
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   208
 *   |
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   209
 *  \|/
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   210
 * Main
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
static const char * SetExecname(char **argv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
static jboolean GetJVMPath(const char *jrepath, const char *jvmtype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                           char *jvmpath, jint jvmpathsize, const char * arch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
static jboolean GetJREPath(char *path, jint pathsize, const char * arch, jboolean speculative);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
#define GetArch() GetArchPath(CURRENT_DATA_MODEL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
const char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
GetArchPath(int nbits)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    switch(nbits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
#ifdef DUAL_MODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        case 32:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return LIBARCH32NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        case 64:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            return LIBARCH64NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
#endif /* DUAL_MODE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            return LIBARCHNAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   236
#ifdef SETENV_REQUIRED
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   237
static jboolean
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   238
JvmExists(const char *path) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   239
    char tmp[PATH_MAX + 1];
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   240
    struct stat statbuf;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   241
    JLI_Snprintf(tmp, PATH_MAX, "%s/%s", path, JVM_DLL);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   242
    if (stat(tmp, &statbuf) == 0) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   243
        return JNI_TRUE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   244
    }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   245
    return JNI_FALSE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   246
}
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   247
/*
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   248
 * contains a lib/$LIBARCH/{server,client}/libjvm.so ?
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   249
 */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   250
static jboolean
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   251
ContainsLibJVM(int wanted, const char *env) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   252
    char clientPattern[PATH_MAX + 1];
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   253
    char serverPattern[PATH_MAX + 1];
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   254
    char *envpath;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   255
    char *path;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   256
    jboolean clientPatternFound;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   257
    jboolean serverPatternFound;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   258
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   259
    /* fastest path */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   260
    if (env == NULL) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   261
        return JNI_FALSE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   262
    }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   263
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   264
    /* the usual suspects */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   265
    JLI_Snprintf(clientPattern, PATH_MAX, "lib/%s/client", GetArchPath(wanted));
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   266
    JLI_Snprintf(serverPattern, PATH_MAX, "lib/%s/server", GetArchPath(wanted));
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   267
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   268
    /* to optimize for time, test if any of our usual suspects are present. */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   269
    clientPatternFound = JLI_StrStr(env, clientPattern) != NULL;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   270
    serverPatternFound = JLI_StrStr(env, serverPattern) != NULL;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   271
    if (clientPatternFound == JNI_FALSE && serverPatternFound == JNI_FALSE) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   272
        return JNI_FALSE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   273
    }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   274
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   275
    /*
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   276
     * we have a suspicious path component, check if it contains a libjvm.so
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   277
     */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   278
    envpath = JLI_StringDup(env);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   279
    for (path = JLI_StrTok(envpath, ":"); path != NULL; path = JLI_StrTok(NULL, ":")) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   280
        if (clientPatternFound && JLI_StrStr(path, clientPattern) != NULL) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   281
            if (JvmExists(path)) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   282
                JLI_MemFree(envpath);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   283
                return JNI_TRUE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   284
            }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   285
        }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   286
        if (serverPatternFound && JLI_StrStr(path, serverPattern)  != NULL) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   287
            if (JvmExists(path)) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   288
                JLI_MemFree(envpath);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   289
                return JNI_TRUE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   290
            }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   291
        }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   292
    }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   293
    JLI_MemFree(envpath);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   294
    return JNI_FALSE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   295
}
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   296
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   297
/*
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   298
 * Test whether the environment variable needs to be set, see flowchart.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   299
 */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   300
static jboolean
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   301
RequiresSetenv(int wanted, const char *jvmpath) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   302
    char jpath[PATH_MAX + 1];
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   303
    char *llp;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   304
    char *dmllp = NULL;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   305
    char *p; /* a utility pointer */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   306
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   307
    llp = getenv("LD_LIBRARY_PATH");
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   308
#ifdef __solaris__
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   309
    dmllp = (CURRENT_DATA_MODEL == 32)
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   310
            ? getenv("LD_LIBRARY_PATH_32")
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   311
            : getenv("LD_LIBRARY_PATH_64");
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   312
#endif /* __solaris__ */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   313
    /* no environment variable is a good environment variable */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   314
    if (llp == NULL && dmllp == NULL) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   315
        return JNI_FALSE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   316
    }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   317
#ifdef __linux
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   318
    /*
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   319
     * On linux, if a binary is running as sgid or suid, glibc sets
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   320
     * LD_LIBRARY_PATH to the empty string for security purposes. (In contrast,
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   321
     * on Solaris the LD_LIBRARY_PATH variable for a privileged binary does not
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   322
     * lose its settings; but the dynamic linker does apply more scrutiny to the
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   323
     * path.) The launcher uses the value of LD_LIBRARY_PATH to prevent an exec
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   324
     * loop, here and further downstream. Therefore, if we are running sgid or
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   325
     * suid, this function's setting of LD_LIBRARY_PATH will be ineffective and
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   326
     * we should case a return from the calling function.  Getting the right
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   327
     * libraries will be handled by the RPATH. In reality, this check is
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   328
     * redundant, as the previous check for a non-null LD_LIBRARY_PATH will
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   329
     * return back to the calling function forthwith, it is left here to safe
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   330
     * guard against any changes, in the glibc's existing security policy.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   331
     */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   332
    if ((getgid() != getegid()) || (getuid() != geteuid())) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   333
        return JNI_FALSE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   334
    }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   335
#endif /* __linux */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   336
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   337
    /*
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   338
     * Prevent recursions. Since LD_LIBRARY_PATH is the one which will be set by
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   339
     * previous versions of the JRE, thus it is the only path that matters here.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   340
     * So we check to see if the desired JRE is set.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   341
     */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   342
    JLI_StrNCpy(jpath, jvmpath, PATH_MAX);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   343
    p = JLI_StrRChr(jpath, '/');
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   344
    *p = '\0';
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   345
    if (llp != NULL && JLI_StrNCmp(llp, jpath, JLI_StrLen(jpath)) == 0) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   346
        return JNI_FALSE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   347
    }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   348
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   349
    /* scrutinize all the paths further */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   350
    if (llp != NULL &&  ContainsLibJVM(wanted, llp)) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   351
        return JNI_TRUE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   352
    }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   353
    if (dmllp != NULL && ContainsLibJVM(wanted, dmllp)) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   354
        return JNI_TRUE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   355
    }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   356
    return JNI_FALSE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   357
}
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   358
#endif /* SETENV_REQUIRED */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   359
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
void
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   361
CreateExecutionEnvironment(int *pargc, char ***pargv,
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   362
                           char jrepath[], jint so_jrepath,
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   363
                           char jvmpath[], jint so_jvmpath) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
  /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
   * First, determine if we are running the desired data model.  If we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
   * are running the desired data model, all the error messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
   * associated with calling GetJREPath, ReadKnownVMs, etc. should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
   * output.  However, if we are not running the desired data model,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
   * some of the errors should be suppressed since it is more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
   * informative to issue an error message based on whether or not the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
   * os/processor combination has dual mode capabilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    jboolean jvmpathExists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /* Compute/set the name of the executable */
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   376
    SetExecname(*pargv);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   378
    /* Check data model flags, and exec process, if needed */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
      char *arch        = (char *)GetArch(); /* like sparc or sparcv9 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
      char * jvmtype    = NULL;
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   382
      int  argc         = *pargc;
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   383
      char **argv       = *pargv;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
      int running       = CURRENT_DATA_MODEL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
      int wanted        = running;      /* What data mode is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                                           asked for? Current model is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                                           fine unless another model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                                           is asked for */
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   390
#ifdef SETENV_REQUIRED
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   391
      jboolean mustsetenv = JNI_FALSE;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   392
      char *runpath     = NULL; /* existing effective LD_LIBRARY_PATH setting */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   393
      char* new_runpath = NULL; /* desired new LD_LIBRARY_PATH string */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   394
      char* newpath     = NULL; /* path on new LD_LIBRARY_PATH */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   395
      char* lastslash   = NULL;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   396
      char** newenvp    = NULL; /* current environment */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   397
#ifdef __solaris__
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   398
      char*  dmpath     = NULL;  /* data model specific LD_LIBRARY_PATH,
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   399
                                    Solaris only */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   400
#endif /* __solaris__ */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   401
#endif  /* SETENV_REQUIRED */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
      char** newargv    = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
      int    newargc    = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
       * Starting in 1.5, all unix platforms accept the -d32 and -d64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
       * options.  On platforms where only one data-model is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
       * (e.g. ia-64 Linux), using the flag for the other data model is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
       * an error and will terminate the program.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
      { /* open new scope to declare local variables */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   416
        newargv = (char **)JLI_MemAlloc((argc+1) * sizeof(char*));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        newargv[newargc++] = argv[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        /* scan for data model arguments and remove from argument list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
           last occurrence determines desired data model */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        for (i=1; i < argc; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
          if (JLI_StrCmp(argv[i], "-J-d64") == 0 || JLI_StrCmp(argv[i], "-d64") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            wanted = 64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
          if (JLI_StrCmp(argv[i], "-J-d32") == 0 || JLI_StrCmp(argv[i], "-d32") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            wanted = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
          newargv[newargc++] = argv[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
          if (IsJavaArgs()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            if (argv[i][0] != '-') continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            if (JLI_StrCmp(argv[i], "-classpath") == 0 || JLI_StrCmp(argv[i], "-cp") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
              i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
              if (i >= argc) break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
              newargv[newargc++] = argv[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
              continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            if (argv[i][0] != '-') { i++; break; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        /* copy rest of args [i .. argc) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        while (i < argc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
          newargv[newargc++] = argv[i++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        newargv[newargc] = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
         * newargv has all proper arguments here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        argc = newargc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        argv = newargv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
      /* If the data model is not changing, it is an error if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
         jvmpath does not exist */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
      if (wanted == running) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        /* Find out where the JRE is that we will be using. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        if (!GetJREPath(jrepath, so_jrepath, arch, JNI_FALSE) ) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   465
          JLI_ReportErrorMessage(JRE_ERROR1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
          exit(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        /* Find the specified JVM type */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        if (ReadKnownVMs(jrepath, arch, JNI_FALSE) < 1) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   471
          JLI_ReportErrorMessage(CFG_ERROR7);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
          exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        jvmpath[0] = '\0';
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   476
        jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   477
        if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   478
            JLI_ReportErrorMessage(CFG_ERROR9);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   479
            exit(4);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   480
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch )) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   483
          JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
          exit(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        }
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   486
        /*
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   487
         * we seem to have everything we need, so without further ado
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   488
         * we return back, otherwise proceed to set the environment.
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   489
         */
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   490
#ifdef SETENV_REQUIRED
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   491
        mustsetenv = RequiresSetenv(wanted, jvmpath);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   492
        JLI_TraceLauncher("mustsetenv: %s\n", mustsetenv ? "TRUE" : "FALSE");
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   493
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   494
        if (mustsetenv == JNI_FALSE) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   495
            return;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   496
        }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   497
#else
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
   498
        return;
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   499
#endif /* SETENV_REQUIRED */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
      } else {  /* do the same speculatively or exit */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
#ifdef DUAL_MODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        if (running != wanted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
          /* Find out where the JRE is that we will be using. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
          if (!GetJREPath(jrepath, so_jrepath, GetArchPath(wanted), JNI_TRUE)) {
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   505
            /* give up and let other code report error message */
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   506
            JLI_ReportErrorMessage(JRE_ERROR2, wanted);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   507
            exit(1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
          /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
           * Read in jvm.cfg for target data model and process vm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
           * selection options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
           */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
          if (ReadKnownVMs(jrepath, GetArchPath(wanted), JNI_TRUE) < 1) {
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   515
            /* give up and let other code report error message */
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   516
            JLI_ReportErrorMessage(JRE_ERROR2, wanted);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   517
            exit(1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
          jvmpath[0] = '\0';
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   520
          jvmtype = CheckJvmType(pargc, pargv, JNI_TRUE);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   521
          if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   522
            JLI_ReportErrorMessage(CFG_ERROR9);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   523
            exit(4);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   524
          }
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   525
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
          /* exec child can do error checking on the existence of the path */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
          jvmpathExists = GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, GetArchPath(wanted));
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   528
#ifdef SETENV_REQUIRED
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   529
          mustsetenv = RequiresSetenv(wanted, jvmpath);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   530
#endif /* SETENV_REQUIRED */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
#else
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   533
        JLI_ReportErrorMessage(JRE_ERROR2, wanted);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
#endif
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   536
        }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   537
#ifdef SETENV_REQUIRED
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   538
        if (mustsetenv) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   539
            /*
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   540
             * We will set the LD_LIBRARY_PATH as follows:
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   541
             *
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   542
             *     o          $JVMPATH (directory portion only)
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   543
             *     o          $JRE/lib/$LIBARCHNAME
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   544
             *     o          $JRE/../lib/$LIBARCHNAME
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   545
             *
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   546
             * followed by the user's previous effective LD_LIBRARY_PATH, if
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   547
             * any.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   548
             */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   549
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   550
#ifdef __solaris__
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   551
            /*
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   552
             * Starting in Solaris 7, ld.so.1 supports three LD_LIBRARY_PATH
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   553
             * variables:
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   554
             *
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   555
             * 1. LD_LIBRARY_PATH -- used for 32 and 64 bit searches if
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   556
             * data-model specific variables are not set.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   557
             *
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   558
             * 2. LD_LIBRARY_PATH_64 -- overrides and replaces LD_LIBRARY_PATH
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   559
             * for 64-bit binaries.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   560
             *
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   561
             * 3. LD_LIBRARY_PATH_32 -- overrides and replaces LD_LIBRARY_PATH
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   562
             * for 32-bit binaries.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   563
             *
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   564
             * The vm uses LD_LIBRARY_PATH to set the java.library.path system
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   565
             * property.  To shield the vm from the complication of multiple
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   566
             * LD_LIBRARY_PATH variables, if the appropriate data model
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   567
             * specific variable is set, we will act as if LD_LIBRARY_PATH had
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   568
             * the value of the data model specific variant and the data model
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   569
             * specific variant will be unset.  Note that the variable for the
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   570
             * *wanted* data model must be used (if it is set), not simply the
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   571
             * current running data model.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   572
             */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   573
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   574
            switch (wanted) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   575
                case 0:
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   576
                    if (running == 32) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   577
                        dmpath = getenv("LD_LIBRARY_PATH_32");
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   578
                        wanted = 32;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   579
                    } else {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   580
                        dmpath = getenv("LD_LIBRARY_PATH_64");
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   581
                        wanted = 64;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   582
                    }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   583
                    break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   585
                case 32:
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   586
                    dmpath = getenv("LD_LIBRARY_PATH_32");
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   587
                    break;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   588
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   589
                case 64:
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   590
                    dmpath = getenv("LD_LIBRARY_PATH_64");
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   591
                    break;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   592
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   593
                default:
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   594
                    JLI_ReportErrorMessage(JRE_ERROR3, __LINE__);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   595
                    exit(1); /* unknown value in wanted */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   596
                    break;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   597
            }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   598
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   599
            /*
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   600
             * If dmpath is NULL, the relevant data model specific variable is
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   601
             * not set and normal LD_LIBRARY_PATH should be used.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   602
             */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   603
            if (dmpath == NULL) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   604
                runpath = getenv("LD_LIBRARY_PATH");
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   605
            } else {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   606
                runpath = dmpath;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   607
            }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   608
#else
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   609
            /*
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   610
             * If not on Solaris, assume only a single LD_LIBRARY_PATH
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   611
             * variable.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   612
             */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   613
            runpath = getenv("LD_LIBRARY_PATH");
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   614
#endif /* __solaris__ */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   615
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   616
            /* runpath contains current effective LD_LIBRARY_PATH setting */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   617
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   618
            jvmpath = JLI_StringDup(jvmpath);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   619
            new_runpath = JLI_MemAlloc(((runpath != NULL) ? JLI_StrLen(runpath) : 0) +
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   620
                    2 * JLI_StrLen(jrepath) + 2 * JLI_StrLen(arch) +
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   621
                    JLI_StrLen(jvmpath) + 52);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   622
            newpath = new_runpath + JLI_StrLen("LD_LIBRARY_PATH=");
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   623
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   624
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   625
            /*
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   626
             * Create desired LD_LIBRARY_PATH value for target data model.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   627
             */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   628
            {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   629
                /* remove the name of the .so from the JVM path */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   630
                lastslash = JLI_StrRChr(jvmpath, '/');
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   631
                if (lastslash)
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   632
                    *lastslash = '\0';
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   633
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   634
                sprintf(new_runpath, "LD_LIBRARY_PATH="
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   635
                        "%s:"
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   636
                        "%s/lib/%s:"
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   637
                        "%s/../lib/%s",
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   638
                        jvmpath,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
#ifdef DUAL_MODE
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   640
                        jrepath, GetArchPath(wanted),
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   641
                        jrepath, GetArchPath(wanted)
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   642
#else
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   643
                        jrepath, arch,
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   644
                        jrepath, arch
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   645
#endif
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   646
                        );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   649
                /*
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   650
                 * Check to make sure that the prefix of the current path is the
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   651
                 * desired environment variable setting, though the RequiresSetenv
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   652
                 * checks if the desired runpath exists, this logic does a more
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   653
                 * comprehensive check.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   654
                 */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   655
                if (runpath != NULL &&
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   656
                        JLI_StrNCmp(newpath, runpath, JLI_StrLen(newpath)) == 0 &&
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   657
                        (runpath[JLI_StrLen(newpath)] == 0 || runpath[JLI_StrLen(newpath)] == ':') &&
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   658
                        (running == wanted) /* data model does not have to be changed */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   659
#ifdef __solaris__
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   660
                        && (dmpath == NULL) /* data model specific variables not set  */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   661
#endif
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   662
                        ) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   663
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   664
                    return;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   665
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   666
                }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   667
            }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   668
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   669
            /*
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   670
             * Place the desired environment setting onto the prefix of
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   671
             * LD_LIBRARY_PATH.  Note that this prevents any possible infinite
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   672
             * loop of execv() because we test for the prefix, above.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   673
             */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   674
            if (runpath != 0) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   675
                JLI_StrCat(new_runpath, ":");
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   676
                JLI_StrCat(new_runpath, runpath);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   677
            }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   678
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   679
            if (putenv(new_runpath) != 0) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   680
                exit(1); /* problem allocating memory; LD_LIBRARY_PATH not set
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   681
                    properly */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   682
            }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   683
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   684
            /*
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   685
             * Unix systems document that they look at LD_LIBRARY_PATH only
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   686
             * once at startup, so we have to re-exec the current executable
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   687
             * to get the changed environment variable to have an effect.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   688
             */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   689
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   690
#ifdef __solaris__
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   691
            /*
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   692
             * If dmpath is not NULL, remove the data model specific string
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   693
             * in the environment for the exec'ed child.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   694
             */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   695
            if (dmpath != NULL)
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   696
                (void)UnsetEnv((wanted == 32) ? "LD_LIBRARY_PATH_32" : "LD_LIBRARY_PATH_64");
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   697
#endif
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   698
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   699
            newenvp = environ;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        }
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   701
#endif /* SETENV_REQUIRED */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   702
        {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   703
            char *newexec = execname;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   704
#ifdef DUAL_MODE
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   705
            /*
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   706
             * If the data model is being changed, the path to the
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   707
             * executable must be updated accordingly; the executable name
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   708
             * and directory the executable resides in are separate.  In the
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   709
             * case of 32 => 64, the new bits are assumed to reside in, e.g.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   710
             * "olddir/LIBARCH64NAME/execname"; in the case of 64 => 32,
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   711
             * the bits are assumed to be in "olddir/../execname".  For example,
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   712
             *
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   713
             * olddir/sparcv9/execname
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   714
             * olddir/amd64/execname
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   715
             *
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   716
             * for Solaris SPARC and Linux amd64, respectively.
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   717
             */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   718
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   719
            if (running != wanted) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   720
                char *oldexec = JLI_StrCpy(JLI_MemAlloc(JLI_StrLen(execname) + 1), execname);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   721
                char *olddir = oldexec;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   722
                char *oldbase = JLI_StrRChr(oldexec, '/');
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   723
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   724
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   725
                newexec = JLI_MemAlloc(JLI_StrLen(execname) + 20);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   726
                *oldbase++ = 0;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   727
                sprintf(newexec, "%s/%s/%s", olddir,
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   728
                        ((wanted == 64) ? LIBARCH64NAME : ".."), oldbase);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   729
                argv[0] = newexec;
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   730
            }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   731
#endif /* DUAL_MODE */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   732
            JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n");
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   733
            (void) fflush(stdout);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   734
            (void) fflush(stderr);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   735
#ifdef SETENV_REQUIRED
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   736
            if (mustsetenv) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   737
                execve(newexec, argv, newenvp);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   738
            } else {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   739
                execv(newexec, argv);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   740
            }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   741
#else
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   742
            execv(newexec, argv);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   743
#endif /* SETENV_REQUIRED */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   744
            JLI_ReportErrorMessageSys(JRE_ERROR4, newexec);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
#ifdef DUAL_MODE
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   747
            if (running != wanted) {
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   748
                JLI_ReportErrorMessage(JRE_ERROR5, wanted, running);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   749
#ifdef __solaris__
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   750
#ifdef __sparc
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   751
                JLI_ReportErrorMessage(JRE_ERROR6);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   752
#else
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   753
                JLI_ReportErrorMessage(JRE_ERROR7);
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   754
#endif  /* __sparc */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   755
            }
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   756
#endif /* __solaris__ */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   757
#endif /* DUAL_MODE */
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   758
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        }
9244
84d85c90d5db 7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents: 7028
diff changeset
   760
        exit(1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
 * On Solaris VM choosing is done by the launcher (java.c).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
GetJVMPath(const char *jrepath, const char *jvmtype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
           char *jvmpath, jint jvmpathsize, const char * arch)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    struct stat s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    if (JLI_StrChr(jvmtype, '/')) {
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   774
        JLI_Snprintf(jvmpath, jvmpathsize, "%s/" JVM_DLL, jvmtype);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    } else {
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   776
        JLI_Snprintf(jvmpath, jvmpathsize, "%s/lib/%s/%s/" JVM_DLL, jrepath, arch, jvmtype);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    JLI_TraceLauncher("Does `%s' exist ... ", jvmpath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    if (stat(jvmpath, &s) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        JLI_TraceLauncher("yes.\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        JLI_TraceLauncher("no.\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
 * Find path to JRE based on .exe's location or registry settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
GetJREPath(char *path, jint pathsize, const char * arch, jboolean speculative)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    char libjava[MAXPATHLEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    if (GetApplicationHome(path, pathsize)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        /* Is JRE co-located with the application? */
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   800
        JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/%s/" JAVA_DLL, path, arch);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        if (access(libjava, F_OK) == 0) {
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   802
            JLI_TraceLauncher("JRE path is %s\n", path);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   803
            return JNI_TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        /* Does the app ship a private JRE in <apphome>/jre directory? */
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   807
        JLI_Snprintf(libjava, sizeof(libjava), "%s/jre/lib/%s/" JAVA_DLL, path, arch);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        if (access(libjava, F_OK) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            JLI_StrCat(path, "/jre");
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   810
            JLI_TraceLauncher("JRE path is %s\n", path);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   811
            return JNI_TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    if (!speculative)
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   816
      JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    void *libjvm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    JLI_TraceLauncher("JVM path is %s\n", jvmpath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    libjvm = dlopen(jvmpath, RTLD_NOW + RTLD_GLOBAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    if (libjvm == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
#if defined(__solaris__) && defined(__sparc) && !defined(_LP64) /* i.e. 32-bit sparc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
      FILE * fp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
      Elf32_Ehdr elf_head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
      int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
      int location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
      fp = fopen(jvmpath, "r");
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   836
      if (fp == NULL) {
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   837
        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   838
        return JNI_FALSE;
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   839
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
      /* read in elf header */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
      count = fread((void*)(&elf_head), sizeof(Elf32_Ehdr), 1, fp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
      fclose(fp);
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   844
      if (count < 1) {
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   845
        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   846
        return JNI_FALSE;
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   847
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
       * Check for running a server vm (compiled with -xarch=v8plus)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
       * on a stock v8 processor.  In this case, the machine type in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
       * the elf header would not be included the architecture list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
       * provided by the isalist command, which is turn is gotten from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
       * sysinfo.  This case cannot occur on 64-bit hardware and thus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
       * does not have to be checked for in binaries with an LP64 data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
       * model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
       */
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   858
      if (elf_head.e_machine == EM_SPARC32PLUS) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        char buf[257];  /* recommended buffer size from sysinfo man
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                           page */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        long length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        char* location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        length = sysinfo(SI_ISALIST, buf, 257);
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   865
        if (length > 0) {
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   866
            location = JLI_StrStr(buf, "sparcv8plus ");
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   867
          if (location == NULL) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   868
            JLI_ReportErrorMessage(JVM_ERROR3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
#endif
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   874
        JLI_ReportErrorMessage(DLL_ERROR1, __LINE__);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   875
        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   876
        return JNI_FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    ifn->CreateJavaVM = (CreateJavaVM_t)
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   880
        dlsym(libjvm, "JNI_CreateJavaVM");
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   881
    if (ifn->CreateJavaVM == NULL) {
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   882
        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   883
        return JNI_FALSE;
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   884
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    ifn->GetDefaultJavaVMInitArgs = (GetDefaultJavaVMInitArgs_t)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        dlsym(libjvm, "JNI_GetDefaultJavaVMInitArgs");
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   888
    if (ifn->GetDefaultJavaVMInitArgs == NULL) {
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   889
        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   890
        return JNI_FALSE;
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   891
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
 * If app is "/foo/bin/javac", or "/foo/bin/sparcv9/javac" then put
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
 * "/foo" into buf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
GetApplicationHome(char *buf, jint bufsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    if (execname != NULL) {
6535
77ffd0e75bfb 6390477: (launcher) replace unsafe usages of sprintf with snprintf
ksrini
parents: 6005
diff changeset
   904
        JLI_Snprintf(buf, bufsize, "%s", execname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        buf[bufsize-1] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    if (JLI_StrRChr(buf, '/') == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        buf[0] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    *(JLI_StrRChr(buf, '/')) = '\0';    /* executable file      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    if (JLI_StrLen(buf) < 4 || JLI_StrRChr(buf, '/') == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        buf[0] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    if (JLI_StrCmp("/bin", buf + JLI_StrLen(buf) - 4) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        *(JLI_StrRChr(buf, '/')) = '\0';        /* sparcv9 or amd64     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    if (JLI_StrLen(buf) < 4 || JLI_StrCmp("/bin", buf + JLI_StrLen(buf) - 4) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        buf[0] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    *(JLI_StrRChr(buf, '/')) = '\0';    /* bin                  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
 * Return true if the named program exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
ProgramExists(char *name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    struct stat sb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    if (stat(name, &sb) != 0) return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    if (S_ISDIR(sb.st_mode)) return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    return (sb.st_mode & S_IEXEC) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
 * Find a command in a directory, returning the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
Resolve(char *indir, char *cmd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    char name[PATH_MAX + 2], *real;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    if ((JLI_StrLen(indir) + JLI_StrLen(cmd) + 1)  > PATH_MAX) return 0;
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   953
    JLI_Snprintf(name, sizeof(name), "%s%c%s", indir, FILE_SEPARATOR, cmd);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    if (!ProgramExists(name)) return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    real = JLI_MemAlloc(PATH_MAX + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    if (!realpath(name, real))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        JLI_StrCpy(real, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    return real;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
 * Find a path for the executable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
FindExecName(char *program)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    char cwdbuf[PATH_MAX+2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    char *path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    char *tmp_path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    char *f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    char *result = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    /* absolute path? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    if (*program == FILE_SEPARATOR ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        (FILE_SEPARATOR=='\\' && JLI_StrRChr(program, ':')))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        return Resolve("", program+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    /* relative path? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    if (JLI_StrRChr(program, FILE_SEPARATOR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        char buf[PATH_MAX+2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        return Resolve(getcwd(cwdbuf, sizeof(cwdbuf)), program);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    /* from search path? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    path = getenv("PATH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    if (!path || !*path) path = ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    tmp_path = JLI_MemAlloc(JLI_StrLen(path) + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    JLI_StrCpy(tmp_path, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    for (f=tmp_path; *f && result==0; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        char *s = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        while (*f && (*f != PATH_SEPARATOR)) ++f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        if (*f) *f++ = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        if (*s == FILE_SEPARATOR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            result = Resolve(s, program);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            /* relative path element */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            char dir[2*PATH_MAX];
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
  1000
            JLI_Snprintf(dir, sizeof(dir), "%s%c%s", getcwd(cwdbuf, sizeof(cwdbuf)),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                    FILE_SEPARATOR, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            result = Resolve(dir, program);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        if (result != 0) break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    JLI_MemFree(tmp_path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
 * Compute the name of the executable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
 * In order to re-exec securely we need the absolute path of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
 * executable. On Solaris getexecname(3c) may not return an absolute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
 * path so we use dladdr to get the filename of the executable and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
 * then use realpath to derive an absolute path. From Solaris 9
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
 * onwards the filename returned in DL_info structure from dladdr is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
 * an absolute pathname so technically realpath isn't required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
 * On Linux we read the executable name from /proc/self/exe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
 * As a fallback, and for platforms other than Solaris and Linux,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
 * we use FindExecName to compute the executable name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
static const char*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
SetExecname(char **argv)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    char* exec_path = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
#if defined(__solaris__)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        Dl_info dlinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        int (*fptr)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        fptr = (int (*)())dlsym(RTLD_DEFAULT, "main");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        if (fptr == NULL) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
  1037
            JLI_ReportErrorMessage(DLL_ERROR3, dlerror());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        if (dladdr((void*)fptr, &dlinfo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            char *resolved = (char*)JLI_MemAlloc(PATH_MAX+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            if (resolved != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                exec_path = realpath(dlinfo.dli_fname, resolved);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                if (exec_path == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                    JLI_MemFree(resolved);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
#elif defined(__linux__)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        const char* self = "/proc/self/exe";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        char buf[PATH_MAX+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        int len = readlink(self, buf, PATH_MAX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        if (len >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            buf[len] = '\0';            /* readlink doesn't nul terminate */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            exec_path = JLI_StringDup(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
#else /* !__solaris__ && !__linux */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        /* Not implemented */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    if (exec_path == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        exec_path = FindExecName(argv[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    execname = exec_path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    return exec_path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
  1074
void JLI_ReportErrorMessage(const char* fmt, ...) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    va_list vl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    va_start(vl, fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    vfprintf(stderr, fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    fprintf(stderr, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    va_end(vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
  1082
void JLI_ReportErrorMessageSys(const char* fmt, ...) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    va_list vl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    char *emsg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * TODO: its safer to use strerror_r but is not available on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     * Solaris 8. Until then....
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    emsg = strerror(errno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    if (emsg != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        fprintf(stderr, "%s\n", emsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    va_start(vl, fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    vfprintf(stderr, fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    fprintf(stderr, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    va_end(vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
  1101
void  JLI_ReportExceptionDescription(JNIEnv * env) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
  (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
 *      Since using the file system as a registry is a bit risky, perform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
 *      additional sanity checks on the identified directory to validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
 *      it as a valid jre/sdk.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
 *      Return 0 if the tests fail; otherwise return non-zero (true).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
 *      Note that checking for anything more than the existence of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
 *      executable object at bin/java relative to the path being checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
 *      will break the regression tests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
CheckSanity(char *path, char *dir)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    char    buffer[PATH_MAX];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    if (JLI_StrLen(path) + JLI_StrLen(dir) + 11 > PATH_MAX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        return (0);     /* Silently reject "impossibly" long paths */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
  1124
    JLI_Snprintf(buffer, sizeof(buffer), "%s/%s/bin/java", path, dir);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    return ((access(buffer, X_OK) == 0) ? 1 : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
 *      Determine if there is an acceptable JRE in the directory dirname.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
 *      Upon locating the "best" one, return a fully qualified path to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
 *      it. "Best" is defined as the most advanced JRE meeting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
 *      constraints contained in the manifest_info. If no JRE in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
 *      directory meets the constraints, return NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
 *      Note that we don't check for errors in reading the directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
 *      (which would be done by checking errno).  This is because it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
 *      doesn't matter if we get an error reading the directory, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
 *      we just don't find anything interesting in the directory.  We
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
 *      just return NULL in either case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
 *      The historical names of j2sdk and j2re were changed to jdk and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
 *      jre respecively as part of the 1.5 rebranding effort.  Since the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
 *      former names are legacy on Linux, they must be recognized for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
 *      all time.  Fortunately, this is a minor cost.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
static char
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
*ProcessDir(manifest_info *info, char *dirname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    DIR     *dirp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    struct dirent *dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    char    *best = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    int     offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    int     best_offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    char    *ret_str = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
    char    buffer[PATH_MAX];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    if ((dirp = opendir(dirname)) == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        return (NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        if ((dp = readdir(dirp)) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            if ((JLI_StrNCmp(dp->d_name, "jre", 3) == 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                (JLI_StrNCmp(dp->d_name, "jdk", 3) == 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                offset = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            else if (JLI_StrNCmp(dp->d_name, "j2re", 4) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                offset = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            else if (JLI_StrNCmp(dp->d_name, "j2sdk", 5) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                offset = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            if (offset > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                if ((JLI_AcceptableRelease(dp->d_name + offset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                    info->jre_version)) && CheckSanity(dirname, dp->d_name))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                    if ((best == NULL) || (JLI_ExactVersionId(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                      dp->d_name + offset, best + best_offset) > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                        if (best != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                            JLI_MemFree(best);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                        best = JLI_StringDup(dp->d_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                        best_offset = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    } while (dp != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    (void) closedir(dirp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    if (best == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        return (NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        ret_str = JLI_MemAlloc(JLI_StrLen(dirname) + JLI_StrLen(best) + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        sprintf(ret_str, "%s/%s", dirname, best);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        JLI_MemFree(best);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        return (ret_str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
 *      This is the global entry point. It examines the host for the optimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
 *      JRE to be used by scanning a set of directories.  The set of directories
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
 *      is platform dependent and can be overridden by the environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
 *      variable JAVA_VERSION_PATH.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
 *      This routine itself simply determines the set of appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
 *      directories before passing control onto ProcessDir().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
char*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
LocateJRE(manifest_info* info)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
    char        *path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
    char        *home;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
    char        *target = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    char        *dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
    char        *cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * Start by getting JAVA_VERSION_PATH
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    if (info->jre_restrict_search) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        path = JLI_StringDup(system_dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    } else if ((path = getenv("JAVA_VERSION_PATH")) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        path = JLI_StringDup(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        if ((home = getenv("HOME")) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            path = (char *)JLI_MemAlloc(JLI_StrLen(home) + \
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                        JLI_StrLen(system_dir) + JLI_StrLen(user_dir) + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            sprintf(path, "%s%s:%s", home, user_dir, system_dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            path = JLI_StringDup(system_dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * Step through each directory on the path. Terminate the scan with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * the first directory with an acceptable JRE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    cp = dp = path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
    while (dp != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        cp = JLI_StrChr(dp, (int)':');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        if (cp != NULL)
7028
adadd244f506 6989469: (launcher) compiler warnings in jli native code
ksrini
parents: 6535
diff changeset
  1237
            *cp = '\0';
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        if ((target = ProcessDir(info, dp)) != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        dp = cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        if (dp != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            dp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
    JLI_MemFree(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    return (target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
 * Given a path to a jre to execute, this routine checks if this process
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
 * is indeed that jre.  If not, it exec's that jre.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
 * We want to actually check the paths rather than just the version string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
 * built into the executable, so that given version specification (and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
 * JAVA_VERSION_PATH) will yield the exact same Java environment, regardless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
 * of the version of the arbitrary launcher we start with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
ExecJRE(char *jre, char **argv)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    char    wanted[PATH_MAX];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    const char* progname = GetProgramName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * Resolve the real path to the directory containing the selected JRE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    if (realpath(jre, wanted) == NULL) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
  1267
        JLI_ReportErrorMessage(JRE_ERROR9, jre);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * Resolve the real path to the currently running launcher.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    SetExecname(argv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    if (execname == NULL) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
  1276
        JLI_ReportErrorMessage(JRE_ERROR10);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * If the path to the selected JRE directory is a match to the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * portion of the path to the currently executing JRE, we have a winner!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     * If so, just return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    if (JLI_StrNCmp(wanted, execname, JLI_StrLen(wanted)) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        return;                 /* I am the droid you were looking for */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     * This should never happen (because of the selection code in SelectJRE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     * but check for "impossibly" long path names just because buffer overruns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     * can be so deadly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    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
  1295
        JLI_ReportErrorMessage(JRE_ERROR11);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * Construct the path and exec it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    (void)JLI_StrCat(JLI_StrCat(wanted, "/bin/"), progname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    argv[0] = JLI_StringDup(progname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    if (JLI_IsTraceLauncher()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        printf("ReExec Command: %s (%s)\n", wanted, argv[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        printf("ReExec Args:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        for (i = 1; argv[i] != NULL; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            printf(" %s", argv[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    }
4340
ec6ba551fa78 6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents: 3834
diff changeset
  1312
    JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    (void)fflush(stdout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
    (void)fflush(stderr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    execv(wanted, argv);
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
  1316
    JLI_ReportErrorMessageSys(JRE_ERROR12, wanted);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
    exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
 * "Borrowed" from Solaris 10 where the unsetenv() function is being added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
 * to libc thanks to SUSv3 (Standard Unix Specification, version 3). As
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
 * such, in the fullness of time this will appear in libc on all relevant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
 * Solaris/Linux platforms and maybe even the Windows platform.  At that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
 * time, this stub can be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
 * This implementation removes the environment locking for multithreaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
 * applications.  (We don't have access to these mutexes within libc and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
 * the launcher isn't multithreaded.)  Note that what remains is platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
 * independent, because it only relies on attributes that a POSIX environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
 * defines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
 * Returns 0 on success, -1 on failure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
 * Also removed was the setting of errno.  The only value of errno set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
 * was EINVAL ("Invalid Argument").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
 * s1(environ) is name=value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
 * s2(name) is name(not the form of name=value).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
 * if names match, return value of 1, else return 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
match_noeq(const char *s1, const char *s2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        while (*s1 == *s2++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
                if (*s1++ == '=')
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
                        return (1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        if (*s1 == '=' && s2[-1] == '\0')
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
                return (1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
 * added for SUSv3 standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
 * Delete entry from environ.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
 * Do not free() memory!  Other threads may be using it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
 * Keep it around forever.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
borrowed_unsetenv(const char *name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        long    idx;            /* index into environ */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        if (name == NULL || *name == '\0' ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            JLI_StrChr(name, '=') != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                return (-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        for (idx = 0; environ[idx] != NULL; idx++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                if (match_noeq(environ[idx], name))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        if (environ[idx] == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                /* name not found but still a success */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        /* squeeze up one entry */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                environ[idx] = environ[idx+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        } while (environ[++idx] != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
/* --- End of "borrowed" code --- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
 * Wrapper for unsetenv() function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
UnsetEnv(char *name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
    return(borrowed_unsetenv(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
/* --- Splash Screen shared library support --- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
static const char* SPLASHSCREEN_SO = "libsplashscreen.so";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
static void* hSplashLib = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
void* SplashProcAddress(const char* name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
    if (!hSplashLib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
        hSplashLib = dlopen(SPLASHSCREEN_SO, RTLD_LAZY | RTLD_GLOBAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
    if (hSplashLib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        void* sym = dlsym(hSplashLib, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
        return sym;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
void SplashFreeLibrary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
    if (hSplashLib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        dlclose(hSplashLib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        hSplashLib = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
const char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
jlong_format_specifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
    return "%lld";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
 * Block current thread and continue execution in a new thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
    int rslt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
    pthread_t tid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
    pthread_attr_t attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
    pthread_attr_init(&attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
    if (stack_size > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
      pthread_attr_setstacksize(&attr, stack_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
    if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
      void * tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
      pthread_join(tid, &tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
      rslt = (int)tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
      * Continue execution in current thread if for some reason (e.g. out of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
      * memory/LWP)  a new thread can't be created. This will likely fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
      * later in continuation as JNI_CreateJavaVM needs to create quite a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
      * few new threads, anyway, just give it a try..
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
      rslt = continuation(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
    pthread_attr_destroy(&attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
    thread_t tid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
    long flags = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
    if (thr_create(NULL, stack_size, (void *(*)(void *))continuation, args, flags, &tid) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
      void * tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
      thr_join(tid, NULL, &tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
      rslt = (int)tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
      /* See above. Continue in current thread if thr_create() failed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
      rslt = continuation(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
    return rslt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
/* Coarse estimation of number of digits assuming the worst case is a 64-bit pid. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
#define MAX_PID_STR_SZ   20
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
void SetJavaLauncherPlatformProps() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
   /* Linux only */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
    const char *substr = "-Dsun.java.launcher.pid=";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
    char *pid_prop_str = (char *)JLI_MemAlloc(JLI_StrLen(substr) + MAX_PID_STR_SZ + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
    sprintf(pid_prop_str, "%s%d", substr, getpid());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
    AddOption(pid_prop_str, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
IsJavaw()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
    /* noop on UNIX */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
}
39
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1496
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1497
void
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1498
InitLauncher(jboolean javaw)
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1499
{
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1500
    JLI_SetTraceLauncher();
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1501
}
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1502
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1503
/*
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1504
 * The implementation for finding classes from the bootstrap
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1505
 * class loader, refer to java.h
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1506
 */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1507
static FindClassFromBootLoader_t *findBootClass = NULL;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1508
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1509
jclass
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1510
FindBootStrapClass(JNIEnv *env, const char* classname)
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1511
{
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1512
   if (findBootClass == NULL) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1513
       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
  1514
          "JVM_FindClassFromBootLoader");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1515
       if (findBootClass == NULL) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1516
           JLI_ReportErrorMessage(DLL_ERROR4,
3834
16342ebd576d 6864028: Update the java launcher to use the new entry point JVM_FindClassFromBootLoader
mchung
parents: 1331
diff changeset
  1517
               "JVM_FindClassFromBootLoader");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1518
           return NULL;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1519
       }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1520
   }
3834
16342ebd576d 6864028: Update the java launcher to use the new entry point JVM_FindClassFromBootLoader
mchung
parents: 1331
diff changeset
  1521
   return findBootClass(env, classname);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1522
}