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; }
int java_init(euca_opts *args, java_home_t *data) { jint (*hotspot_main)(JavaVM **, JNIEnv **, JavaVMInitArgs *); char *libjvm_path=NULL; if ((libjvm_path=java_library(args,data))==NULL) __fail("Cannot locate JVM library file"); dso_handle libjvm_handle=NULL; __die((libjvm_handle=dlopen(libjvm_path,RTLD_GLOBAL|RTLD_NOW))==NULL,"Cannot dynamically link to %s\n%s",libjvm_path,dso_error()); __debug("JVM library %s loaded",libjvm_path); if ((hotspot_main=dlsym(libjvm_handle,"JNI_CreateJavaVM"))==NULL) __fail("Cannot find JVM library entry point"); JavaVMInitArgs arg; arg.ignoreUnrecognized=0; #if defined(JNI_VERSION_1_4) arg.version=JNI_VERSION_1_4; #else arg.version=JNI_VERSION_1_2; #endif JavaVMOption *opt=NULL; char* java_class_path = java_library_path(args); __debug("Using classpath:\n%s",java_class_path); #define JVM_MAX_OPTS 128 int x = -1, i = 0; opt=(JavaVMOption *)malloc(JVM_MAX_OPTS*sizeof(JavaVMOption)); for(i=0;i<JVM_MAX_OPTS;i++) opt[i].extraInfo=NULL; i = -1; while(jvm_default_opts[++i]!= NULL) JVM_ARG(opt[++x],jvm_default_opts[i],GETARG(args,home)); if(args->exhaustive_flag) { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.db=TRACE"); JVM_ARG(opt[++x],"-Deuca.log.exhaustive.user=TRACE"); JVM_ARG(opt[++x],"-Deuca.log.exhaustive.cc=TRACE"); JVM_ARG(opt[++x],"-Deuca.log.exhaustive.external=TRACE"); } else { if(args->exhaustive_db_flag) { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.db=TRACE"); } else { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.db=FATAL"); } if(args->exhaustive_cc_flag) { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.cc=TRACE"); } else { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.cc=FATAL"); } if(args->exhaustive_user_flag) { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.user=TRACE"); } else { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.user=FATAL"); } if(args->exhaustive_external_flag) { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.external=TRACE"); } else { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.external=FATAL"); } } JVM_ARG(opt[++x],"-Deuca.log.level=%1$s",GETARG(args,log_level)); JVM_ARG(opt[++x],"-Deuca.log.appender=%1$s",GETARG(args,log_appender)); JVM_ARG(opt[++x],"-Deuca.db.port=%1$d",9001);//TODO: add cli parameter JVM_ARG(opt[++x],"-Deuca.db.host=%1$s",GETARG(args,cloud_host)); JVM_ARG(opt[++x],"-Deuca.walrus.host=%1$s",GETARG(args,walrus_host)); if(args->disable_dns_flag) { JVM_ARG(opt[++x],"-Deuca.disable.dns=true"); } if(args->disable_storage_flag) { JVM_ARG(opt[++x],"-Deuca.disable.storage=true"); } if(args->disable_cloud_flag) { JVM_ARG(opt[++x],"-Deuca.disable.eucalyptus=true"); } if(args->disable_walrus_flag) { JVM_ARG(opt[++x],"-Deuca.disable.walrus=true"); } if(args->remote_dns_flag) { JVM_ARG(opt[++x],"-Deuca.remote.dns=true"); } if(args->remote_storage_flag) { JVM_ARG(opt[++x],"-Deuca.remote.storage=true"); } if(args->remote_cloud_flag) { JVM_ARG(opt[++x],"-Deuca.remote.cloud=true"); } if(args->remote_walrus_flag) { JVM_ARG(opt[++x],"-Deuca.remote.walrus=true"); } if(args->disable_iscsi_flag) { JVM_ARG(opt[++x],"-Deuca.disable.iscsi=true"); } if(args->debug_flag) { JVM_ARG(opt[++x],"-Xdebug"); JVM_ARG(opt[++x],"-Xrunjdwp:transport=dt_socket,server=y,suspend=%2$s,address=%1$d",GETARG(args,debug_port),(args->debug_suspend_flag?"y":"n")); } if(args->debug_flag||args->profile_flag) { JVM_ARG(opt[++x],"-Dcom.sun.management.jmxremote"); JVM_ARG(opt[++x],"-XX:+HeapDumpOnOutOfMemoryError"); JVM_ARG(opt[++x],"-XX:HeapDumpPath=%s/var/log/eucalyptus/",GETARG(args,home)); } if(args->profile_flag && args->agentlib_given ) { JVM_ARG(opt[++x],"-agentlib:%s",GETARG(args,agentlib)); } else if(args->profile_flag) { JVM_ARG(opt[++x],"-agentlib:jprofilerti=port=8849"); JVM_ARG(opt[++x],"-Xbootclasspath/a:%1$s/bin/agent.jar",GETARG(args,profiler_home)); } for (i=0; i<args->jvm_args_given; i++) JVM_ARG(opt[++x],"-X%s",args->jvm_args_arg[i]); for (i=0; i<args->define_given; i++) JVM_ARG(opt[++x],"-D%s",args->define_arg[i]); opt[++x].optionString=java_class_path; opt[x].extraInfo=NULL; opt[++x].optionString="abort"; opt[x].extraInfo=java_fail; arg.nOptions = x+1; arg.options=opt; if (debug) { __debug("+-------------------------------------------------------"); __debug("| Version: %x", arg.version); __debug("| Ignore Unrecognized Arguments: %d", arg.ignoreUnrecognized); __debug("| Extra options: %d", arg.nOptions); for (x=0; x<arg.nOptions; x++) __debug("| \"%-80.80s\" (0x%p)",opt[x].optionString, opt[x].extraInfo); __debug("+-------------------------------------------------------"); } __debug("Starting JVM."); jint ret = 0; while((ret=(*hotspot_main)(&jvm, &env, &arg)==123)); __die(ret<0,"Failed to create JVM"); java_load_bootstrapper(); return 1; }
int java_init(euca_opts *args, java_home_t *data) { jint (*hotspot_main)(JavaVM **, JNIEnv **, JavaVMInitArgs *); char *libjvm_path = NULL; if ((libjvm_path = java_library(args, data)) == NULL) __fail("Cannot locate JVM library file"); dso_handle libjvm_handle = NULL; __die( (libjvm_handle = dlopen(libjvm_path, RTLD_GLOBAL | RTLD_NOW)) == NULL, "Cannot dynamically link to %s\n%s", libjvm_path, dso_error()); __debug("JVM library %s loaded", libjvm_path); if ((hotspot_main = dlsym(libjvm_handle, "JNI_CreateJavaVM")) == NULL) __fail("Cannot find JVM library entry point"); JavaVMInitArgs arg; arg.ignoreUnrecognized = 0; #if defined(JNI_VERSION_1_4) arg.version=JNI_VERSION_1_4; #else arg.version = JNI_VERSION_1_2; #endif JavaVMOption *opt = NULL; char* java_class_path = java_library_path(args); __debug("Using classpath:\n%s", java_class_path); #define JVM_MAX_OPTS 128 int x = -1, i = 0; opt = (JavaVMOption *) malloc(JVM_MAX_OPTS * sizeof(JavaVMOption)); for (i = 0; i < JVM_MAX_OPTS; i++) opt[i].extraInfo = NULL; i = -1; while (jvm_default_opts[++i] != NULL) JVM_ARG(opt[++x], jvm_default_opts[i], GETARG(args, home)); if (args->exhaustive_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive=TRACE"); JVM_ARG(opt[++x], "-Deuca.log.exhaustive.db=TRACE"); JVM_ARG(opt[++x], "-Deuca.log.exhaustive.user=TRACE"); JVM_ARG(opt[++x], "-Deuca.log.exhaustive.cc=TRACE"); JVM_ARG(opt[++x], "-Deuca.log.exhaustive.external=TRACE"); } else { int exhaust = 0; if (args->exhaustive_db_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.db=TRACE"); exhaust++; } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.db=FATAL"); } if (args->exhaustive_cc_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.cc=TRACE"); exhaust++; } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.cc=FATAL"); } if (args->exhaustive_user_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.user=TRACE"); exhaust++; } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.user=FATAL"); } if (args->exhaustive_external_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.external=TRACE"); exhaust++; } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.external=FATAL"); } if (exhaust) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive=TRACE"); } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive=FATAL"); } } JVM_ARG(opt[++x], "-Deuca.version=%1$s", ARGUMENTS_VERSION); JVM_ARG(opt[++x], "-Deuca.log.level=%1$s", GETARG(args, log_level)); JVM_ARG(opt[++x], "-Deuca.log.appender=%1$s", GETARG(args, log_appender)); if (strlen(GETARG(args, extra_version)) > 1 && strncmp(GETARG(args, extra_version), "@", 1)) { JVM_ARG(opt[++x], "-Deuca.extra_version=%1$s", GETARG(args, extra_version)); } if (args->initialize_flag) { JVM_ARG(opt[++x], "-Deuca.initialize=true"); JVM_ARG(opt[++x], "-Deuca.remote.dns=true"); } else { if (args->remote_dns_flag) { JVM_ARG(opt[++x], "-Deuca.remote.dns=true"); } if (args->disable_iscsi_flag) { JVM_ARG(opt[++x], "-Deuca.disable.iscsi=true"); } } if (args->force_remote_bootstrap_flag || args->disable_cloud_flag) { JVM_ARG(opt[++x], "-Deuca.force.remote.bootstrap=true"); } if (args->debug_noha_flag) { JVM_ARG(opt[++x], "-Deuca.noha.cloud"); } if (args->db_home_given) { JVM_ARG(opt[++x], "-Deuca.db.home=%s", GETARG(args, db_home)); } if (args->debug_flag) { JVM_ARG(opt[++x], "-XX:+HeapDumpOnOutOfMemoryError"); JVM_ARG(opt[++x], "-XX:HeapDumpPath=%s/var/log/eucalyptus/", GETARG(args, home)); JVM_ARG(opt[++x], "-Xdebug"); JVM_ARG( opt[++x], "-Xrunjdwp:transport=dt_socket,server=y,suspend=%2$s,address=%1$d", GETARG(args, debug_port), (args->debug_suspend_flag ? "y" : "n")); } if (args->jmx_flag || args->debug_flag) { JVM_ARG(opt[++x], "-Dcom.sun.management.jmxremote");//TODO:GRZE:wrapup jmx stuff here. JVM_ARG(opt[++x], "-Dcom.sun.management.jmxremote.port=8772"); JVM_ARG(opt[++x], "-Dcom.sun.management.jmxremote.authenticate=false");//TODO:GRZE:RELEASE FIXME to use ssl JVM_ARG(opt[++x], "-Dcom.sun.management.jmxremote.ssl=false"); } if (args->verbose_flag ) { JVM_ARG(opt[++x], "-verbose:gc"); JVM_ARG(opt[++x], "-XX:+PrintGCTimeStamps"); JVM_ARG(opt[++x], "-XX:+PrintGCDetails"); } if (args->profile_flag && args->agentlib_given) { JVM_ARG(opt[++x], "-agentlib:%s", GETARG(args, agentlib)); } else if (args->profile_flag) { JVM_ARG(opt[++x], "-agentlib:jprofilerti=port=8849"); JVM_ARG(opt[++x], "-Xbootclasspath/a:%1$s/bin/agent.jar", GETARG(args, profiler_home)); } if (args->user_given) { JVM_ARG(opt[++x], "-Deuca.user=%s", GETARG(args, user)); } for (i = 0; i < args->jvm_args_given; i++) JVM_ARG(opt[++x], "-X%s", args->jvm_args_arg[i]); for (i = 0; i < args->define_given; i++) JVM_ARG(opt[++x], "-D%s", args->define_arg[i]); for (i = 0; i < args->bootstrap_host_given; i++) JVM_ARG(opt[++x], "-Deuca.bootstrap.host.%d=%s", i, args->bootstrap_host_arg[i]); for (i = 0; i < args->bind_addr_given; i++) JVM_ARG(opt[++x], "-Deuca.bind.addr.%d=%s", i, args->bind_addr_arg[i]); opt[++x].optionString = java_class_path; opt[x].extraInfo = NULL; opt[++x].optionString = "abort"; opt[x].extraInfo = java_fail; arg.nOptions = x + 1; arg.options = opt; if (debug) { __debug("+-------------------------------------------------------"); if (strlen(GETARG(args, extra_version)) > 1 && strncmp(GETARG(args, extra_version), "@", 1)) __debug("| Eucalyptus version: %s-%s", ARGUMENTS_VERSION, GETARG(args, extra_version)); else __debug("| Eucalyptus version: %s", ARGUMENTS_VERSION); __debug("| JNI version: %x", arg.version); __debug("| Ignore Unrecognized Arguments: %d", arg.ignoreUnrecognized); __debug("| Extra options: %d", arg.nOptions); for (x = 0; x < arg.nOptions; x++) __debug("| \"%-80.80s\" (0x%p)", opt[x].optionString, opt[x].extraInfo); __debug("+-------------------------------------------------------"); } __debug("Starting JVM."); jint ret = 0; while ((ret = (*hotspot_main)(&jvm, &env, &arg) == 123)) ; __die(ret < 0, "Failed to create JVM"); java_load_bootstrapper(); dlclose(libjvm_handle); return 1; }
int java_init(euca_opts * args, java_home_t * data) { jint(*hotspot_main) (JavaVM **, JNIEnv **, JavaVMInitArgs *); char *libjvm_path = NULL; if ((libjvm_path = java_library(args, data)) == NULL) __fail("Cannot locate JVM library file"); dso_handle libjvm_handle = NULL; __die((libjvm_handle = dlopen(libjvm_path, RTLD_GLOBAL | RTLD_NOW)) == NULL, "Cannot dynamically link to %s\n%s", libjvm_path, dso_error()); __debug("JVM library %s loaded", libjvm_path); if ((hotspot_main = dlsym(libjvm_handle, "JNI_CreateJavaVM")) == NULL) __fail("Cannot find JVM library entry point"); JavaVMInitArgs arg; arg.ignoreUnrecognized = 0; #if defined(JNI_VERSION_1_4) arg.version = JNI_VERSION_1_4; #else arg.version = JNI_VERSION_1_2; #endif JavaVMOption *opt = NULL; char *java_class_path = java_library_path(args); __debug("Using classpath:\n%s", java_class_path); #define JVM_MAX_OPTS 128 int x = -1, i = 0, encoding_not_defined_flag = 1; opt = (JavaVMOption *) malloc(JVM_MAX_OPTS * sizeof(JavaVMOption)); for (i = 0; i < JVM_MAX_OPTS; i++) opt[i].extraInfo = NULL; i = -1; while (jvm_default_opts[++i] != NULL) JVM_ARG(opt[++x], jvm_default_opts[i], GETARG(args, home)); // setting heap size to half of total memory if it was not set by user char *s, str[16], size_i; long size; str[0] = 0; for (i = 0; i < args->jvm_args_given; i++) { if ((s = strstr(args->jvm_args_arg[i], "mx")) && sscanf(s, "mx%s", str) == 1) { break; } } if (str[0] != 0) { sscanf (str,"%ld%c", &size, &size_i); switch(size_i) { case 'k' : case 'K' : size = size * 1024L; break; case 'm' : case 'M' : size = size * 1024L * 1024L; break; case 'g' : case 'G' : size = size * GIG; break; default: size = size * 1L; } __debug("User defined heap size is %ld bytes", size); if (size < GIG) { __error("User defined heap size of %ld bytes is set too low and system might now work properly", size); } } else { size_t total_memory = getMemoryTotalSize(); double heap_size_gb = 2; if (total_memory <= 32 * GIG && total_memory >= 4 * GIG) heap_size_gb = ceil(total_memory/GIG/2.0); else if (total_memory > 32 * GIG) heap_size_gb = 16.0; __info("User did not set heap size. Setting it automatically to %.0lfGB base on total memory of %zu bytes", heap_size_gb, total_memory); JVM_ARG(opt[++x], "-Xms%.0lfg", heap_size_gb); JVM_ARG(opt[++x], "-Xmx%.0lfg", heap_size_gb); } if (args->exhaustive_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive=TRACE"); JVM_ARG(opt[++x], "-Deuca.log.exhaustive.db=TRACE"); JVM_ARG(opt[++x], "-Deuca.log.exhaustive.user=TRACE"); JVM_ARG(opt[++x], "-Deuca.log.exhaustive.cc=TRACE"); JVM_ARG(opt[++x], "-Deuca.log.exhaustive.external=TRACE"); } else { int exhaust = 0; if (args->exhaustive_db_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.db=TRACE"); exhaust++; } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.db=FATAL"); } if (args->exhaustive_cc_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.cc=TRACE"); exhaust++; } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.cc=FATAL"); } if (args->exhaustive_user_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.user=TRACE"); exhaust++; } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.user=FATAL"); } if (args->exhaustive_external_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.external=TRACE"); exhaust++; } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.external=FATAL"); } if (exhaust) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive=TRACE"); } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive=FATAL"); } } JVM_ARG(opt[++x], "-Deuca.version=%1$s", ARGUMENTS_VERSION); JVM_ARG(opt[++x], "-Deuca.log.level=%1$s", GETARG(args, log_level)); JVM_ARG(opt[++x], "-Deuca.log.appender=%1$s", GETARG(args, log_appender)); if (strlen(GETARG(args, extra_version)) > 1 && strncmp(GETARG(args, extra_version), "@", 1)) { JVM_ARG(opt[++x], "-Deuca.extra_version=%1$s", GETARG(args, extra_version)); } if (args->initialize_flag) { JVM_ARG(opt[++x], "-Deuca.initialize=true"); JVM_ARG(opt[++x], "-Deuca.remote.dns=true"); } else if (args->upgrade_flag) { JVM_ARG(opt[++x], "-Deuca.upgrade=true"); if (args->upgrade_force_flag) { JVM_ARG(opt[++x], "-Deuca.upgrade.force=true"); } JVM_ARG(opt[++x], "-Deuca.upgrade.old.dir=%1$s", GETARG(args, upgrade_old_dir)); JVM_ARG(opt[++x], "-Deuca.upgrade.old.version=%1$s", GETARG(args, upgrade_old_version)); } else { if (args->remote_dns_flag) { JVM_ARG(opt[++x], "-Deuca.remote.dns=true"); } if (args->disable_iscsi_flag) { JVM_ARG(opt[++x], "-Deuca.disable.iscsi=true"); } } if (args->force_remote_bootstrap_flag || args->disable_cloud_flag) { JVM_ARG(opt[++x], "-Deuca.force.remote.bootstrap=true"); } if (args->debug_noha_flag) { JVM_ARG(opt[++x], "-Deuca.noha.cloud"); } if (args->db_home_given) { JVM_ARG(opt[++x], "-Deuca.db.home=%s", GETARG(args, db_home)); } JVM_ARG(opt[++x], "-XX:+HeapDumpOnOutOfMemoryError"); JVM_ARG(opt[++x], "-XX:HeapDumpPath=%s/var/log/eucalyptus/", GETARG(args, home)); if (args->debug_flag) { JVM_ARG(opt[++x], "-agentlib:jdwp=transport=dt_socket,server=y,suspend=%2$s,address=%1$d", GETARG(args, debug_port), (args->debug_suspend_flag ? "y" : "n")); } if (args->jmx_flag) { JVM_ARG(opt[++x], "-Dcom.sun.management.jmxremote"); //TODO:GRZE:wrapup jmx stuff here. JVM_ARG(opt[++x], "-Dcom.sun.management.jmxremote.port=8772"); JVM_ARG(opt[++x], "-Dcom.sun.management.jmxremote.authenticate=false"); //TODO:GRZE:RELEASE FIXME to use ssl JVM_ARG(opt[++x], "-Dcom.sun.management.jmxremote.ssl=false"); } if (args->verbose_flag) { JVM_ARG(opt[++x], "-verbose:gc"); JVM_ARG(opt[++x], "-XX:+PrintGCTimeStamps"); JVM_ARG(opt[++x], "-XX:+PrintGCDetails"); } if (args->profile_flag && args->agentlib_given) { JVM_ARG(opt[++x], "-agentlib:%s", GETARG(args, agentlib)); } else if (args->profile_flag) { JVM_ARG(opt[++x], "-agentlib:jprofilerti=port=8849"); JVM_ARG(opt[++x], "-Xbootclasspath/a:%1$s/bin/agent.jar", GETARG(args, profiler_home)); } if (args->user_given) { JVM_ARG(opt[++x], "-Deuca.user=%s", GETARG(args, user)); } for (i = 0; i < args->jvm_args_given; i++) JVM_ARG(opt[++x], "-X%s", args->jvm_args_arg[i]); for (i = 0; i < args->define_given; i++) { JVM_ARG(opt[++x], "-D%s", args->define_arg[i]); if (strncmp(args->define_arg[i], "file.encoding", 13) == 0) encoding_not_defined_flag = 0; } for (i = 0; i < args->bootstrap_host_given; i++) JVM_ARG(opt[++x], "-Deuca.bootstrap.host.%d=%s", i, args->bootstrap_host_arg[i]); for (i = 0; i < args->bind_addr_given; i++) JVM_ARG(opt[++x], "-Deuca.bind.addr.%d=%s", i, args->bind_addr_arg[i]); if (args->mcast_addr_given) { JVM_ARG(opt[++x], "-Deuca.mcast.addr=%s", GETARG(args, mcast_addr)); } if (encoding_not_defined_flag) JVM_ARG(opt[++x], "-Dfile.encoding=UTF-8"); opt[++x].optionString = java_class_path; opt[x].extraInfo = NULL; opt[++x].optionString = "abort"; opt[x].extraInfo = java_fail; arg.nOptions = x + 1; arg.options = opt; if (debug) { __debug("+-------------------------------------------------------"); if (strlen(GETARG(args, extra_version)) > 1 && strncmp(GETARG(args, extra_version), "@", 1)) __debug("| Eucalyptus version: %s-%s", ARGUMENTS_VERSION, GETARG(args, extra_version)); else __debug("| Eucalyptus version: %s", ARGUMENTS_VERSION); __debug("| JNI version: %x", arg.version); __debug("| Ignore Unrecognized Arguments: %d", arg.ignoreUnrecognized); __debug("| Extra options: %d", arg.nOptions); for (x = 0; x < arg.nOptions; x++) __debug("| \"%-80.80s\" (0x%p)", opt[x].optionString, opt[x].extraInfo); __debug("+-------------------------------------------------------"); } __debug("Starting JVM."); jint ret = 0; while ((ret = (*hotspot_main) (&jvm, &env, &arg) == EUCA_RET_RELOAD)) ; __die(ret < 0, "Failed to create JVM"); java_load_bootstrapper(); dlclose(libjvm_handle); return 1; }
/* 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; }