499
500 /*
501 * If dmpath is NULL, the relevant data model specific variable is
502 * not set and normal LD_LIBRARY_PATH should be used.
503 */
504 if (dmpath == NULL) {
505 runpath = getenv("LD_LIBRARY_PATH");
506 } else {
507 runpath = dmpath;
508 }
509 #else /* ! __solaris__ */
510 /*
511 * If not on Solaris, assume only a single LD_LIBRARY_PATH
512 * variable.
513 */
514 runpath = getenv(LD_LIBRARY_PATH);
515 #endif /* __solaris__ */
516
517 /* runpath contains current effective LD_LIBRARY_PATH setting */
518
519 jvmpath = JLI_StringDup(jvmpath);
520 new_runpath_size = ((runpath != NULL) ? JLI_StrLen(runpath) : 0) +
521 2 * JLI_StrLen(jrepath) + 2 * JLI_StrLen(arch) +
522 #ifdef AIX
523 /* On AIX we additionally need 'jli' in the path because ld doesn't support $ORIGIN. */
524 JLI_StrLen(jrepath) + JLI_StrLen(arch) + JLI_StrLen("/lib//jli:") +
525 #endif
526 JLI_StrLen(jvmpath) + 52;
527 new_runpath = JLI_MemAlloc(new_runpath_size);
528 newpath = new_runpath + JLI_StrLen(LD_LIBRARY_PATH "=");
529
530
531 /*
532 * Create desired LD_LIBRARY_PATH value for target data model.
533 */
534 {
535 /* remove the name of the .so from the JVM path */
536 lastslash = JLI_StrRChr(jvmpath, '/');
537 if (lastslash)
538 *lastslash = '\0';
539
540 sprintf(new_runpath, LD_LIBRARY_PATH "="
541 "%s:"
542 "%s/lib/%s:"
543 #ifdef AIX
544 "%s/lib/%s/jli:" /* Needed on AIX because ld doesn't support $ORIGIN. */
545 #endif
546 "%s/../lib/%s",
547 jvmpath,
548 jrepath, arch,
549 #ifdef AIX
550 jrepath, arch,
551 #endif
552 jrepath, arch
553 );
554
555
556 /*
557 * Check to make sure that the prefix of the current path is the
558 * desired environment variable setting, though the RequiresSetenv
559 * checks if the desired runpath exists, this logic does a more
560 * comprehensive check.
561 */
562 if (runpath != NULL &&
563 JLI_StrNCmp(newpath, runpath, JLI_StrLen(newpath)) == 0 &&
564 (runpath[JLI_StrLen(newpath)] == 0 || runpath[JLI_StrLen(newpath)] == ':') &&
565 (running == wanted) /* data model does not have to be changed */
566 #ifdef __solaris__
567 && (dmpath == NULL) /* data model specific variables not set */
568 #endif /* __solaris__ */
569 ) {
570 JLI_MemFree(newargv);
571 JLI_MemFree(new_runpath);
572 return;
573 }
574 }
|
499
500 /*
501 * If dmpath is NULL, the relevant data model specific variable is
502 * not set and normal LD_LIBRARY_PATH should be used.
503 */
504 if (dmpath == NULL) {
505 runpath = getenv("LD_LIBRARY_PATH");
506 } else {
507 runpath = dmpath;
508 }
509 #else /* ! __solaris__ */
510 /*
511 * If not on Solaris, assume only a single LD_LIBRARY_PATH
512 * variable.
513 */
514 runpath = getenv(LD_LIBRARY_PATH);
515 #endif /* __solaris__ */
516
517 /* runpath contains current effective LD_LIBRARY_PATH setting */
518
519 char *new_jvmpath = JLI_StringDup(jvmpath);
520 new_runpath_size = ((runpath != NULL) ? JLI_StrLen(runpath) : 0) +
521 2 * JLI_StrLen(jrepath) + 2 * JLI_StrLen(arch) +
522 #ifdef AIX
523 /* On AIX we additionally need 'jli' in the path because ld doesn't support $ORIGIN. */
524 JLI_StrLen(jrepath) + JLI_StrLen(arch) + JLI_StrLen("/lib/jli:") +
525 #endif
526 JLI_StrLen(new_jvmpath) + 52;
527 new_runpath = JLI_MemAlloc(new_runpath_size);
528 newpath = new_runpath + JLI_StrLen(LD_LIBRARY_PATH "=");
529
530
531 /*
532 * Create desired LD_LIBRARY_PATH value for target data model.
533 */
534 {
535 /* remove the name of the .so from the JVM path */
536 lastslash = JLI_StrRChr(new_jvmpath, '/');
537 if (lastslash)
538 *lastslash = '\0';
539
540 sprintf(new_runpath, LD_LIBRARY_PATH "="
541 "%s:"
542 "%s/lib/%s:"
543 #ifdef AIX
544 "%s/lib/%s/jli:" /* Needed on AIX because ld doesn't support $ORIGIN. */
545 #endif
546 "%s/../lib/%s",
547 new_jvmpath,
548 jrepath, arch,
549 #ifdef AIX
550 jrepath, arch,
551 #endif
552 jrepath, arch
553 );
554
555 JLI_MemFree(new_jvmpath);
556
557 /*
558 * Check to make sure that the prefix of the current path is the
559 * desired environment variable setting, though the RequiresSetenv
560 * checks if the desired runpath exists, this logic does a more
561 * comprehensive check.
562 */
563 if (runpath != NULL &&
564 JLI_StrNCmp(newpath, runpath, JLI_StrLen(newpath)) == 0 &&
565 (runpath[JLI_StrLen(newpath)] == 0 || runpath[JLI_StrLen(newpath)] == ':') &&
566 (running == wanted) /* data model does not have to be changed */
567 #ifdef __solaris__
568 && (dmpath == NULL) /* data model specific variables not set */
569 #endif /* __solaris__ */
570 ) {
571 JLI_MemFree(newargv);
572 JLI_MemFree(new_runpath);
573 return;
574 }
575 }
|