< prev index next >

src/java.base/unix/native/libjli/java_md_common.c

Print this page


   1 /*
   2  * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 161     for (f=tmp_path; *f && result==0; ) {
 162         char *s = f;
 163         while (*f && (*f != PATH_SEPARATOR)) ++f;
 164         if (*f) *f++ = 0;
 165         if (*s == FILE_SEPARATOR)
 166             result = Resolve(s, program);
 167         else {
 168             /* relative path element */
 169             char dir[2*PATH_MAX];
 170             JLI_Snprintf(dir, sizeof(dir), "%s%c%s", getcwd(cwdbuf, sizeof(cwdbuf)),
 171                     FILE_SEPARATOR, s);
 172             result = Resolve(dir, program);
 173         }
 174         if (result != 0) break;
 175     }
 176 
 177     JLI_MemFree(tmp_path);
 178     return result;
 179 }
 180 
 181 void JLI_ReportErrorMessage(const char* fmt, ...) {

 182     va_list vl;
 183     va_start(vl, fmt);
 184     vfprintf(stderr, fmt, vl);
 185     fprintf(stderr, "\n");
 186     va_end(vl);
 187 }
 188 
 189 void JLI_ReportErrorMessageSys(const char* fmt, ...) {

 190     va_list vl;
 191     char *emsg;
 192 
 193     /*
 194      * TODO: its safer to use strerror_r but is not available on
 195      * Solaris 8. Until then....
 196      */
 197     emsg = strerror(errno);
 198     if (emsg != NULL) {
 199         fprintf(stderr, "%s\n", emsg);
 200     }
 201 
 202     va_start(vl, fmt);
 203     vfprintf(stderr, fmt, vl);
 204     fprintf(stderr, "\n");
 205     va_end(vl);
 206 }
 207 
 208 void  JLI_ReportExceptionDescription(JNIEnv * env) {

 209   (*env)->ExceptionDescribe(env);
 210 }
 211 
 212 /*
 213  *      Since using the file system as a registry is a bit risky, perform
 214  *      additional sanity checks on the identified directory to validate
 215  *      it as a valid jre/sdk.
 216  *
 217  *      Return 0 if the tests fail; otherwise return non-zero (true).
 218  *
 219  *      Note that checking for anything more than the existence of an
 220  *      executable object at bin/java relative to the path being checked
 221  *      will break the regression tests.
 222  */
 223 static int
 224 CheckSanity(char *path, char *dir)
 225 {
 226     char    buffer[PATH_MAX];
 227 
 228     if (JLI_StrLen(path) + JLI_StrLen(dir) + 11 > PATH_MAX)


 328  * The implementation for finding classes from the bootstrap
 329  * class loader, refer to java.h
 330  */
 331 static FindClassFromBootLoader_t *findBootClass = NULL;
 332 
 333 jclass
 334 FindBootStrapClass(JNIEnv *env, const char* classname)
 335 {
 336    if (findBootClass == NULL) {
 337        findBootClass = (FindClassFromBootLoader_t *)dlsym(RTLD_DEFAULT,
 338           "JVM_FindClassFromBootLoader");
 339        if (findBootClass == NULL) {
 340            JLI_ReportErrorMessage(DLL_ERROR4,
 341                "JVM_FindClassFromBootLoader");
 342            return NULL;
 343        }
 344    }
 345    return findBootClass(env, classname);
 346 }
 347 
 348 StdArg
 349 *JLI_GetStdArgs()
 350 {
 351     return NULL;
 352 }
 353 
 354 int
 355 JLI_GetStdArgc() {
 356     return 0;
 357 }
 358 
 359 jobjectArray
 360 CreateApplicationArgs(JNIEnv *env, char **strv, int argc)
 361 {
 362     return NewPlatformStringArray(env, strv, argc);
 363 }
   1 /*
   2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 161     for (f=tmp_path; *f && result==0; ) {
 162         char *s = f;
 163         while (*f && (*f != PATH_SEPARATOR)) ++f;
 164         if (*f) *f++ = 0;
 165         if (*s == FILE_SEPARATOR)
 166             result = Resolve(s, program);
 167         else {
 168             /* relative path element */
 169             char dir[2*PATH_MAX];
 170             JLI_Snprintf(dir, sizeof(dir), "%s%c%s", getcwd(cwdbuf, sizeof(cwdbuf)),
 171                     FILE_SEPARATOR, s);
 172             result = Resolve(dir, program);
 173         }
 174         if (result != 0) break;
 175     }
 176 
 177     JLI_MemFree(tmp_path);
 178     return result;
 179 }
 180 
 181 JNIEXPORT void JNICALL
 182 JLI_ReportErrorMessage(const char* fmt, ...) {
 183     va_list vl;
 184     va_start(vl, fmt);
 185     vfprintf(stderr, fmt, vl);
 186     fprintf(stderr, "\n");
 187     va_end(vl);
 188 }
 189 
 190 JNIEXPORT void JNICALL
 191 JLI_ReportErrorMessageSys(const char* fmt, ...) {
 192     va_list vl;
 193     char *emsg;
 194 
 195     /*
 196      * TODO: its safer to use strerror_r but is not available on
 197      * Solaris 8. Until then....
 198      */
 199     emsg = strerror(errno);
 200     if (emsg != NULL) {
 201         fprintf(stderr, "%s\n", emsg);
 202     }
 203 
 204     va_start(vl, fmt);
 205     vfprintf(stderr, fmt, vl);
 206     fprintf(stderr, "\n");
 207     va_end(vl);
 208 }
 209 
 210 JNIEXPORT void JNICALL
 211 JLI_ReportExceptionDescription(JNIEnv * env) {
 212   (*env)->ExceptionDescribe(env);
 213 }
 214 
 215 /*
 216  *      Since using the file system as a registry is a bit risky, perform
 217  *      additional sanity checks on the identified directory to validate
 218  *      it as a valid jre/sdk.
 219  *
 220  *      Return 0 if the tests fail; otherwise return non-zero (true).
 221  *
 222  *      Note that checking for anything more than the existence of an
 223  *      executable object at bin/java relative to the path being checked
 224  *      will break the regression tests.
 225  */
 226 static int
 227 CheckSanity(char *path, char *dir)
 228 {
 229     char    buffer[PATH_MAX];
 230 
 231     if (JLI_StrLen(path) + JLI_StrLen(dir) + 11 > PATH_MAX)


 331  * The implementation for finding classes from the bootstrap
 332  * class loader, refer to java.h
 333  */
 334 static FindClassFromBootLoader_t *findBootClass = NULL;
 335 
 336 jclass
 337 FindBootStrapClass(JNIEnv *env, const char* classname)
 338 {
 339    if (findBootClass == NULL) {
 340        findBootClass = (FindClassFromBootLoader_t *)dlsym(RTLD_DEFAULT,
 341           "JVM_FindClassFromBootLoader");
 342        if (findBootClass == NULL) {
 343            JLI_ReportErrorMessage(DLL_ERROR4,
 344                "JVM_FindClassFromBootLoader");
 345            return NULL;
 346        }
 347    }
 348    return findBootClass(env, classname);
 349 }
 350 
 351 JNIEXPORT StdArg JNICALL
 352 *JLI_GetStdArgs()
 353 {
 354     return NULL;
 355 }
 356 
 357 JNIEXPORT int JNICALL
 358 JLI_GetStdArgc() {
 359     return 0;
 360 }
 361 
 362 jobjectArray
 363 CreateApplicationArgs(JNIEnv *env, char **strv, int argc)
 364 {
 365     return NewPlatformStringArray(env, strv, argc);
 366 }
< prev index next >