< prev index next >

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

Print this page




 218             if (JvmExists(path)) {
 219                 JLI_MemFree(envpath);
 220                 return JNI_TRUE;
 221             }
 222         }
 223     }
 224     JLI_MemFree(envpath);
 225     return JNI_FALSE;
 226 }
 227 
 228 /*
 229  * Test whether the environment variable needs to be set, see flowchart.
 230  */
 231 static jboolean
 232 RequiresSetenv(const char *jvmpath) {
 233     char jpath[PATH_MAX + 1];
 234     char *llp;
 235     char *dmllp = NULL;
 236     char *p; /* a utility pointer */
 237 

































 238 #ifdef AIX
 239     /* We always have to set the LIBPATH on AIX because ld doesn't support $ORIGIN. */
 240     return JNI_TRUE;
 241 #endif
 242 
 243     llp = getenv("LD_LIBRARY_PATH");
 244 #ifdef __solaris__
 245     dmllp = getenv("LD_LIBRARY_PATH_64");
 246 #endif /* __solaris__ */
 247     /* no environment variable is a good environment variable */
 248     if (llp == NULL && dmllp == NULL) {
 249         return JNI_FALSE;
 250     }
 251 #ifdef __linux
 252     /*
 253      * On linux, if a binary is running as sgid or suid, glibc sets
 254      * LD_LIBRARY_PATH to the empty string for security purposes. (In contrast,
 255      * on Solaris the LD_LIBRARY_PATH variable for a privileged binary does not
 256      * lose its settings; but the dynamic linker does apply more scrutiny to the
 257      * path.) The launcher uses the value of LD_LIBRARY_PATH to prevent an exec




 218             if (JvmExists(path)) {
 219                 JLI_MemFree(envpath);
 220                 return JNI_TRUE;
 221             }
 222         }
 223     }
 224     JLI_MemFree(envpath);
 225     return JNI_FALSE;
 226 }
 227 
 228 /*
 229  * Test whether the environment variable needs to be set, see flowchart.
 230  */
 231 static jboolean
 232 RequiresSetenv(const char *jvmpath) {
 233     char jpath[PATH_MAX + 1];
 234     char *llp;
 235     char *dmllp = NULL;
 236     char *p; /* a utility pointer */
 237 
 238 #ifdef __linux
 239 #ifndef LIBC
 240 #error "LIBC not set"
 241 #endif
 242 
 243     if (strcmp(LIBC, "musl") == 0) {
 244       /*
 245        * The musl library loader requires LD_LIBRARY_PATH to be set in
 246        * order to correctly resolve the dependency libjava.so has on libjvm.so.
 247        *
 248        * Specifically, it differs from glibc in the sense that even if
 249        * libjvm.so has already been loaded it will not be considered a
 250        * candidate for resolving the dependency unless the *full* path
 251        * of the already loaded library matches the dependency being loaded.
 252        *
 253        * libjvm.so is being loaded by the launcher using a long path to
 254        * dlopen, not just the basename of the library. Typically this
 255        * is something like "../lib/server/libjvm.so". However, if/when
 256        * libjvm.so later tries to dlopen libjava.so (which it does in
 257        * order to get access to a few functions implemented in
 258        * libjava.so) the musl loader will, as part of loading
 259        * dependent libraries, try to load libjvm.so using only its
 260        * basename "libjvm.so". Since this does not match the longer
 261        * path path it was first loaded with, the already loaded
 262        * library is not considered a candidate, and the loader will
 263        * instead look for libjvm.so elsewhere. If it's not in
 264        * LD_LIBRARY_PATH the dependency load will fail, and libjava.so
 265        * will therefore fail as well.
 266        */
 267       return JNI_TRUE;
 268     }
 269 #endif
 270 
 271 #ifdef AIX
 272     /* We always have to set the LIBPATH on AIX because ld doesn't support $ORIGIN. */
 273     return JNI_TRUE;
 274 #endif
 275 
 276     llp = getenv("LD_LIBRARY_PATH");
 277 #ifdef __solaris__
 278     dmllp = getenv("LD_LIBRARY_PATH_64");
 279 #endif /* __solaris__ */
 280     /* no environment variable is a good environment variable */
 281     if (llp == NULL && dmllp == NULL) {
 282         return JNI_FALSE;
 283     }
 284 #ifdef __linux
 285     /*
 286      * On linux, if a binary is running as sgid or suid, glibc sets
 287      * LD_LIBRARY_PATH to the empty string for security purposes. (In contrast,
 288      * on Solaris the LD_LIBRARY_PATH variable for a privileged binary does not
 289      * lose its settings; but the dynamic linker does apply more scrutiny to the
 290      * path.) The launcher uses the value of LD_LIBRARY_PATH to prevent an exec


< prev index next >