static int ld_libcap(void) { int i = 0; dso_handle dso = NULL; #define CAP_LDD(name) \ if ((fp_##name = dso_symbol(dso, #name)) == NULL) { \ log_error("cannot locate " #name " in libcap.so -- %s", dso_error()); \ dso_unlink(dso); \ return -1; \ } else log_debug("loaded " #name " from libcap.") if (hlibcap != NULL) return 0; while (libcap_locs[i] && dso == NULL) { if ((dso = dso_link(libcap_locs[i++]))) break; }; if (dso == NULL) { log_error("failed loading capabilities library -- %s.", dso_error()); return -1; } CAP_LDD(cap_free); CAP_LDD(cap_init); CAP_LDD(cap_clear); CAP_LDD(cap_get_flag); CAP_LDD(cap_set_flag); CAP_LDD(cap_set_proc); hlibcap = dso; #undef CAP_LDD return 0; }
/* Initialize the JVM and its environment, loading libraries and all */ bool java_init(arg_data *args, home_data *data) { #ifdef OS_DARWIN dso_handle apph = NULL; char appf[1024]; struct stat sb; #endif /* ifdef OS_DARWIN */ jvm_create_t symb = NULL; JNINativeMethod nativemethods[2]; JavaVMOption *opt = NULL; dso_handle libh = NULL; JavaVMInitArgs arg; char *libf = NULL; jint ret; int x; char loaderclass[] = LOADER; char shutdownmethod[] = "shutdown"; char shutdownparams[] = "(Z)V"; char failedmethod[] = "failed"; char failedparams[] = "(Ljava/lang/String;)V"; char daemonprocid[64]; /* Decide WHAT virtual machine we need to use */ libf = java_library(args, data); if (libf == NULL) { log_error("Cannot locate JVM library file"); return false; } /* Initialize the DSO library */ if (dso_init() != true) { log_error("Cannot initialize the dynamic library loader"); return false; } /* Load the JVM library */ #if !defined(OSD_POSIX) libh = dso_link(libf); if (libh == NULL) { log_error("Cannot dynamically link to %s", libf); log_error("%s", dso_error()); return false; } log_debug("JVM library %s loaded", libf); #endif #ifdef OS_DARWIN /* MacOS/X actually has two libraries, one with the REAL vm, and one for the VM startup. before JVM 1.4.1 The first one (libappshell.dyld) contains CreateVM JVM 1.4.1 through 1.5.* The library name is libjvm_compat.dylib starting with JVM 1.6 on OS X 10.6 the library name is libverify.dylib. */ if (replace(appf, 1024, "$JAVA_HOME/../Libraries/libappshell.dylib", "$JAVA_HOME", data->path) != 0) { log_error("Cannot replace values in loader library"); return false; } if (stat(appf, &sb)) { if (replace(appf, 1024, "$JAVA_HOME/../Libraries/libjvm_compat.dylib", "$JAVA_HOME", data->path) != 0) { log_error("Cannot replace values in loader library"); return false; } } if (stat(appf, &sb)) { if (replace(appf, 1024, "$JAVA_HOME/../Libraries/libverify.dylib", "$JAVA_HOME", data->path) != 0) { log_error("Cannot replace values in loader library"); return false; } } apph = dso_link(appf); if (apph == NULL) { log_error("Cannot load required shell library %s", appf); return false; } log_debug("Shell library %s loaded", appf); #endif /* ifdef OS_DARWIN */ #if defined(OSD_POSIX) /* BS2000 does not allow to call JNI_CreateJavaVM indirectly */ #else symb = (jvm_create_t)dso_symbol(libh, "JNI_CreateJavaVM"); if (symb == NULL) { #ifdef OS_DARWIN symb = (jvm_create_t)dso_symbol(apph, "JNI_CreateJavaVM"); if (symb == NULL) { #endif /* ifdef OS_DARWIN */ log_error("Cannot find JVM library entry point"); return false; #ifdef OS_DARWIN } #endif /* ifdef OS_DARWIN */ } log_debug("JVM library entry point found (0x%08X)", symb); #endif /* Prepare the VM initialization arguments */ /* * Mac OS X Java will load JVM 1.3.1 instead of 1.4.2 if JNI_VERSION_1_2 * is specified. So use JNI_VERSION_1_4 if we can. */ #if defined(JNI_VERSION_1_4) arg.version = JNI_VERSION_1_4; #else arg.version = JNI_VERSION_1_2; #endif #if defined(OSD_POSIX) if (JNI_GetDefaultJavaVMInitArgs(&arg) < 0) { log_error("Cannot init default JVM default args"); return false; } #endif arg.ignoreUnrecognized = FALSE; arg.nOptions = args->onum + 4; /* pid, ppid and abort */ opt = (JavaVMOption *) malloc(arg.nOptions * sizeof(JavaVMOption)); for (x = 0; x < args->onum; x++) { opt[x].optionString = strdup(args->opts[x]); jsvc_xlate_to_ascii(opt[x].optionString); opt[x].extraInfo = NULL; } /* Add our daemon process id */ snprintf(daemonprocid, sizeof(daemonprocid), "-Dcommons.daemon.process.id=%d", (int)getpid()); opt[x].optionString = strdup(daemonprocid); jsvc_xlate_to_ascii(opt[x].optionString); opt[x++].extraInfo = NULL; snprintf(daemonprocid, sizeof(daemonprocid), "-Dcommons.daemon.process.parent=%d", (int)getppid()); opt[x].optionString = strdup(daemonprocid); jsvc_xlate_to_ascii(opt[x].optionString); opt[x++].extraInfo = NULL; snprintf(daemonprocid, sizeof(daemonprocid), "-Dcommons.daemon.version=%s", JSVC_VERSION_STRING); opt[x].optionString = strdup(daemonprocid); jsvc_xlate_to_ascii(opt[x].optionString); opt[x++].extraInfo = NULL; opt[x].optionString = strdup("abort"); jsvc_xlate_to_ascii(opt[x].optionString); opt[x].extraInfo = (void *)java_abort123; arg.options = opt; /* Do some debugging */ if (log_debug_flag == true) { log_debug("+-- DUMPING JAVA VM CREATION ARGUMENTS -----------------"); log_debug("| Version: %#08x", arg.version); log_debug("| Ignore Unrecognized Arguments: %s", arg.ignoreUnrecognized == TRUE ? "True" : "False"); log_debug("| Extra options: %d", args->onum); for (x = 0; x < args->onum; x++) { jsvc_xlate_from_ascii(opt[x].optionString); log_debug("| \"%s\" (0x%08x)", opt[x].optionString, opt[x].extraInfo); jsvc_xlate_to_ascii(opt[x].optionString); } log_debug("+-------------------------------------------------------"); log_debug("| Internal options: %d", arg.nOptions - args->onum); for (; x < arg.nOptions; x++) { jsvc_xlate_from_ascii(opt[x].optionString); log_debug("| \"%s\" (0x%08x)", opt[x].optionString, opt[x].extraInfo); jsvc_xlate_to_ascii(opt[x].optionString); } log_debug("+-------------------------------------------------------"); } /* And finally create the Java VM */ #if defined(OSD_POSIX) ret = JNI_CreateJavaVM(&jvm, &env, &arg); #else ret = (*symb) (&jvm, &env, &arg); #endif if (ret < 0) { log_error("Cannot create Java VM"); return false; } log_debug("Java VM created successfully"); jsvc_xlate_to_ascii(loaderclass); cls = (*env)->FindClass(env, loaderclass); jsvc_xlate_from_ascii(loaderclass); if (cls == NULL) { log_error("Cannot find daemon loader %s", loaderclass); return false; } log_debug("Class %s found", loaderclass); jsvc_xlate_to_ascii(shutdownmethod); nativemethods[0].name = shutdownmethod; jsvc_xlate_to_ascii(shutdownparams); nativemethods[0].signature = shutdownparams; nativemethods[0].fnPtr = (void *)shutdown; jsvc_xlate_to_ascii(failedmethod); nativemethods[1].name = failedmethod; jsvc_xlate_to_ascii(failedparams); nativemethods[1].signature = failedparams; nativemethods[1].fnPtr = (void *)failed; if ((*env)->RegisterNatives(env, cls, nativemethods, 2) != 0) { log_error("Cannot register native methods"); return false; } log_debug("Native methods registered"); return true; }