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