char* java_library_path(euca_opts *args) {
#define JAVA_PATH_LEN 65536
    char lib_dir[256],etc_dir[256],script_dir[256],*jar_list=(char*)malloc(JAVA_PATH_LEN*sizeof(char));
    __die(( strlen(GETARG(args,home))+strlen(EUCA_LIB_DIR)>=254),"Directory path too long: %s/%s", GETARG(args,home), EUCA_LIB_DIR);
    snprintf(lib_dir,255,"%s%s",GETARG(args,home),EUCA_LIB_DIR);
    snprintf(etc_dir,255,"%s%s",GETARG(args,home),EUCA_ETC_DIR);
    snprintf(script_dir,255,"%s%s",GETARG(args,home),EUCA_SCRIPT_DIR);
    if(!CHECK_ISDIR(lib_dir) ) __die(1,"Can't find library directory %s", lib_dir );
    int wb = 0;
    wb += snprintf(jar_list+wb,JAVA_PATH_LEN-wb,"-Djava.class.path=%s:",etc_dir);
    wb += snprintf(jar_list+wb,JAVA_PATH_LEN-wb,"%s",script_dir);
    DIR* lib_dir_p = opendir(lib_dir);
    struct direct *dir_ent;
    while ((dir_ent = readdir(lib_dir_p))!=0)  {
            if (strcmp(dir_ent->d_name,".") != 0 && strcmp(dir_ent->d_name,"..") != 0 && strcmp(dir_ent->d_name,"openjdk-crypto.jar") != 0 && strstr(dir_ent->d_name,"disabled") == NULL && strstr(dir_ent->d_name,"eucalyptus-") != NULL )  {
                            char jar[256];
                            snprintf(jar,255,"%s/%s",lib_dir,dir_ent->d_name);
                            if( (CHECK_ISREG(jar) || CHECK_ISLNK(jar)) ) wb += snprintf(jar_list+wb,JAVA_PATH_LEN-wb,":%s",jar);
            }
    }
    closedir(lib_dir_p);
    lib_dir_p = opendir(lib_dir);
    while ((dir_ent = readdir(lib_dir_p))!=0)  {
            if (strcmp(dir_ent->d_name,".") != 0 && strcmp(dir_ent->d_name,"..") != 0 && strcmp(dir_ent->d_name,"openjdk-crypto.jar") != 0 && strstr(dir_ent->d_name,"disabled") == NULL && strstr(dir_ent->d_name,"eucalyptus-") == NULL)  {
                            char jar[256];
                            snprintf(jar,255,"%s/%s",lib_dir,dir_ent->d_name);
                            if( (CHECK_ISREG(jar) || CHECK_ISLNK(jar)) ) wb += snprintf(jar_list+wb,JAVA_PATH_LEN-wb,":%s",jar);
            }
    }
    closedir(lib_dir_p);
    return jar_list;
}
static int child(euca_opts * args, java_home_t * data, uid_t uid, gid_t gid)
{
    int ret = 0;
    jboolean r = 0;
    __write_pid(GETARG(args, pidfile));
    setpgrp();
    __limits();
    __die(java_init(args, data) != 1, "Failed to initialize Eucalyptus.");
    __die_jni((r = (*env)->CallBooleanMethod(env, bootstrap.instance, bootstrap.init)) == 0, "Failed to init Eucalyptus.");
    __abort(4, set_keys_ownership(GETARG(args, home), uid, gid) != 0, "Setting ownership of keyfile failed.");
    __abort(4, linuxset_user_group(GETARG(args, user), uid, gid) != 0, "Setting the user failed.");
    __die_jni((r = (*env)->CallBooleanMethod(env, bootstrap.instance, bootstrap.load)) == 0, "Failed to load Eucalyptus.");
    __die_jni((r = (*env)->CallBooleanMethod(env, bootstrap.instance, bootstrap.start)) == 0, "Failed to start Eucalyptus.");
    handle._hup = signal_set(SIGHUP, handler);
    handle._term = signal_set(SIGTERM, handler);
    handle._int = signal_set(SIGINT, handler);
    child_pid = getpid();
    __debug("Waiting for a signal to be delivered");
    while (!stopping)
        sleep(60);
    __debug("Shutdown or reload requested: exiting");
    __die_jni((r = (*env)->CallBooleanMethod(env, bootstrap.instance, bootstrap.stop)) == 0, "Failed to stop Eucalyptus.");
    if (doreload == 1)
        ret = EUCA_RET_RELOAD;
    else
        ret = 0;
    __die_jni((r = (*env)->CallBooleanMethod(env, bootstrap.instance, bootstrap.destroy)) == 0, "Failed to destroy Eucalyptus.");
    __die((JVM_destroy(ret) != 1), "Failed trying to destroy JVM... bailing out seems like the right thing to do");
    return ret;
}
void java_sleep(int wait) {
    jclass clsThread;
    jmethodID method;
    __die( ((clsThread = (*env)->FindClass(env,"java/lang/Thread"))==NULL),"Cannot find java/lang/Thread class");
    __die( ((method=(*env)->GetStaticMethodID(env,clsThread,"sleep","(J)V"))==NULL), "Cannot found the sleep entry point");
    (*env)->CallStaticVoidMethod(env,clsThread,method,(jlong)wait*1000);
}
int JVM_destroy(int code) {
    jclass system;
    jmethodID method;
    __die((system=(*env)->FindClass(env,"java/lang/System"))==NULL,"Cannot find class java/lang/System.");
    __die((method=(*env)->GetStaticMethodID(env,system,"exit","(I)V"))==NULL,"Cannot find \"System.exit(int)\" entry point.");
    __debug("Calling System.exit(%d)",code);
    (*env)->CallStaticVoidMethod(env,system,method,(jint)code);
    if ((*jvm)->DestroyJavaVM(jvm)!=0) return 0;
    __debug("JVM destroyed.");
    return 1;
}
Ejemplo n.º 5
0
/*
 * This function is protected against re-entrancy.
 */
void die(const char *str, struct pt_regs *regs, int err)
{
	enum bug_trap_type bug_type = BUG_TRAP_TYPE_NONE;
	struct thread_info *thread = current_thread_info();
	int ret;

	oops_enter();

	raw_spin_lock_irq(&die_lock);
	console_verbose();
	bust_spinlocks(1);

	if (!user_mode(regs))
		bug_type = report_bug(regs->pc, regs);
	if (bug_type != BUG_TRAP_TYPE_NONE)
		str = "Oops - BUG";

	ret = __die(str, err, thread, regs);

	if (regs && kexec_should_crash(thread->task))
		crash_kexec(regs);

	bust_spinlocks(0);
	add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
	raw_spin_unlock_irq(&die_lock);
	oops_exit();

	if (in_interrupt())
		panic("Fatal exception in interrupt");
	if (panic_on_oops)
		panic("Fatal exception");
	if (ret != NOTIFY_STOP)
		do_exit(SIGSEGV);
}
Ejemplo n.º 6
0
/*
 * This function is protected against re-entrancy.
 */
void die(const char *str, struct pt_regs *regs, int err)
{
	struct thread_info *thread = current_thread_info();
	int ret;

	oops_enter();

	raw_spin_lock_irq(&die_lock);
	console_verbose();
	bust_spinlocks(1);
	ret = __die(str, err, thread, regs);

	if (regs && kexec_should_crash(thread->task))
		crash_kexec(regs);

	bust_spinlocks(0);
	add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
	raw_spin_unlock_irq(&die_lock);
	oops_exit();

	if (in_interrupt())
		panic("Fatal exception in interrupt");
	if (panic_on_oops)
		panic("Fatal exception");
	if (ret != NOTIFY_STOP)
		do_exit(SIGSEGV);
}
Ejemplo n.º 7
0
/*
 * This function is protected against re-entrancy.
 */
void die(const char *str, struct pt_regs *regs, int err)
{
	int ret;
	unsigned long flags;

	raw_spin_lock_irqsave(&die_lock, flags);

	oops_enter();

	console_verbose();
	bust_spinlocks(1);
	ret = __die(str, err, regs);

	if (regs && kexec_should_crash(current))
		crash_kexec(regs);

	bust_spinlocks(0);
	add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
	oops_exit();

	if (in_interrupt())
		panic("Fatal exception in interrupt");
	if (panic_on_oops)
		panic("Fatal exception");

	raw_spin_unlock_irqrestore(&die_lock, flags);

	if (ret != NOTIFY_STOP)
		do_exit(SIGSEGV);
}
Ejemplo n.º 8
0
void die(const char * str, struct pt_regs * regs, long err)
{
	unsigned long flags = oops_begin();

	handle_BUG(regs);
	__die(str, regs, err);
	oops_end(flags);
	do_exit(SIGSEGV); 
}
Ejemplo n.º 9
0
/* Makes the ash region shared */
void 
AllocAshShareRegion(void) {
  /* printf("AllocAshShareRegion sz: %d\n",sizeof(struct ash_sh_network)); */
  if (__vm_alloc_region(ADD_UVA(ASH_PKT_DATA_ADDR),
			sizeof(struct ash_sh_network), 0,
			PG_SHARED|PG_P|PG_U|PG_W) < 0) {
    printf ("couldn't insert ash data pte's\n");
    __die();
  }
}
static int wait_child( euca_opts *args, int pid ) {
	time_t timer=0;
	int rc=0,status;
	while(rc <= 0 && timer < (15000000)) {
		usleep(50000),timer += 50000;
		__die((rc = waitpid(pid, &status, WNOHANG))<0,"Waiting for child failed?!?");
		if( WIFEXITED( status ) ) return WEXITSTATUS( status );
	}
	return 1;
}
Ejemplo n.º 11
0
/*
 * This is gone through when something in the kernel has done something bad
 * and is about to be terminated:
 */
void die(const char *str, struct pt_regs *regs, long err)
{
	unsigned long flags = oops_begin();
	int sig = SIGSEGV;

	if (!user_mode_vm(regs))
		report_bug(regs->ip, regs);

	if (__die(str, regs, err))
		sig = 0;
	oops_end(flags, regs, sig);
}
Ejemplo n.º 12
0
static int stop_child(euca_opts *args) {
	int pid = __get_pid(GETARG(args, pidfile)), rc = 0, i;
	if (pid <= 0)
		return -1;
	fprintf(stderr, "Waiting for process to terminate: pid=%d .", pid);
	for (i = 0; i < 60 && (rc = kill(pid, SIGTERM)) != -1; i++) {
		usleep(1000 * 1000), fprintf(stderr, "."), fflush(stderr);
	}
	if (i == 0) {
		i = errno;
		__die(rc == -1 && i == ESRCH, "No process with the specified pid=%d",
				pid);
		__die(rc == -1 && i == EPERM, "Do not have permission to kill pid=%d",
				pid);
	} else if (i == 60) {
		__debug("Forcefully terminating hung process.");
		kill(pid, SIGKILL);
	} else {
		fprintf(stderr, "\nTerminated process with pid=%d\n", pid);
	}
	return 0;
}
Ejemplo n.º 13
0
/*
 * This is gone through when something in the kernel has done something bad
 * and is about to be terminated:
 */
void die(const char *str, struct pt_regs *regs, long err)
{
	unsigned long flags = oops_begin();

	if (die_nest_count < 3) {
		report_bug(regs->ip, regs);

		if (__die(str, regs, err))
			regs = NULL;
	} else {
		printk(KERN_EMERG "Recursive die() failure, output suppressed\n");
	}

	oops_end(flags, regs, SIGSEGV);
}
static int checkuser( char *user, uid_t *uid, gid_t *gid ) {
	struct passwd *pwds = NULL;
	int status = 0;
	pid_t pid = 0;
	__abort(1, user == NULL,"" );
	pwds = getpwnam( user );
	__abort(0, (pwds == NULL ),"Invalid user name '%s' specified", user );
	*uid = pwds->pw_uid;
	*gid = pwds->pw_gid;
	pid = fork( );
	__abort(0,( pid == -1 ), "Cannot validate user name" );
	if( pid == 0 ) {
		__die( set_user_group( user, *uid, *gid ) != 0,"set_user_group failed." );
		exit( 0 );
	}
	while( waitpid( pid, &status, 0 ) != pid );
	if( WIFEXITED( status ) ) {
		status = WEXITSTATUS( status );
		__abort(0, (status != 0),"User '%s' validated", user );
	}
	return 1;
}
Ejemplo n.º 15
0
/*
 * This function is protected against re-entrancy.
 */
void die(const char *str, struct pt_regs *regs, int err)
{
	struct thread_info *thread = current_thread_info();
	int ret;

#ifdef CONFIG_HUAWEI_PRINTK_CTRL
	printk_level_setup(LOGLEVEL_DEBUG);
#endif

	oops_enter();

	raw_spin_lock_irq(&die_lock);
	console_verbose();
	bust_spinlocks(1);
#ifdef CONFIG_HISI_BB
	set_exception_info(instruction_pointer(regs));
#endif
	ret = __die(str, err, thread, regs);

	if (regs && kexec_should_crash(thread->task))
		crash_kexec(regs);

	bust_spinlocks(0);
	add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
	raw_spin_unlock_irq(&die_lock);
	oops_exit();

	if (in_interrupt())
		panic("Fatal exception in interrupt");
	if (panic_on_oops)
		panic("Fatal exception");
	if (ret != NOTIFY_STOP)
		do_exit(SIGSEGV);
#ifdef CONFIG_HUAWEI_PRINTK_CTRL
	printk_level_setup(sysctl_printk_level);
#endif
}
Ejemplo n.º 16
0
/*
 * This function is protected against re-entrancy.
 */
void die(const char *str, struct pt_regs *regs, int err)
{
	struct thread_info *thread = current_thread_info();
	int ret;

	oops_enter();


#ifdef CCI_KLOG_CRASH_SIZE
#if CCI_KLOG_CRASH_SIZE
	set_fault_state(FAULT_LEVEL_DIE, err, str);
#endif // #if CCI_KLOG_CRASH_SIZE
#endif // #ifdef CCI_KLOG_CRASH_SIZE


	raw_spin_lock_irq(&die_lock);
	console_verbose();
	bust_spinlocks(1);
	ret = __die(str, err, thread, regs);

	if (regs && kexec_should_crash(thread->task))
		crash_kexec(regs);

	bust_spinlocks(0);
	add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
	/* keep preemption/irq disabled in KE flow to prevent context switch*/
	/*raw_spin_unlock_irq(&die_lock);*/
	oops_exit();

	if (in_interrupt())
		panic("Fatal exception in interrupt");
	if (panic_on_oops)
		panic("Fatal exception");
	if (ret != NOTIFY_STOP)
		do_exit(SIGSEGV);
}
Ejemplo n.º 17
0
int main(int argc, char *argv[]) {
	euca_opts euca_args;
	euca_opts *args = &euca_args;
	java_home_t *data = NULL;
	int status = 0;
	pid_t pid = 0;
	uid_t uid = 0;
	gid_t gid = 0;
	int i;
	if (arguments(argc, argv, args) != 0)
		exit(1);
	debug = args->debug_flag;
	set_output(GETARG(args, out), GETARG(args, err));
	if (args->kill_flag == 1)
		return stop_child(args);
	if (checkuser(GETARG(args, user), &uid, &gid) == 0)
		return 1;
	for (i = 0; i < args->java_home_given; ++i) {
		__debug("Trying user supplied java home: %s", args->java_home_arg[i]);
		data = get_java_home(args->java_home_arg[i]);
		if (data != NULL) {
			break;
		}
	}
	char* java_home_env = getenv("JAVA_HOME");
	if (data == NULL && java_home_env != NULL) {
		__debug("Trying environment JAVA_HOME: %s", java_home_env);
		data = get_java_home(java_home_env);
	}
	if (data == NULL && !args->java_home_given && 
            args->java_home_arg[0] != NULL && CHECK_ISDIR(args->java_home_arg[0])) {
		__debug("Trying built-in java home: %s", args->java_home_arg[0]);
		data = get_java_home(args->java_home_arg[0]);
	}
	if (data == NULL && CHECK_ISREG("/usr/bin/java")) {
		char * javapath = (char *) calloc(PATH_MAX, sizeof(char));
		javapath = realpath("/usr/bin/java", javapath);
		if (javapath != NULL) {
			javapath[strlen(javapath)-strlen("jre/bin/java")] = '\0';
			__debug("Trying system java home: %s", javapath);
			data = get_java_home(javapath);
		}
	}
	if (data == NULL) {
		__error("Cannot locate Java Home");
		return 1;
	}
	int x;
	if (debug == 1) {
		__debug("+-- DUMPING JAVA HOME STRUCTURE ------------------------");
		__debug("| Java Home:       \"%s\"", PRINT_NULL(data->path));
		__debug("| Found JVMs:      %d", data->jnum);
		for (x = 0; x < data->jnum; x++) {
			jvm_info_t *jvm = data->jvms[x];
			__debug("| JVM Name:        \"%s\"", PRINT_NULL(jvm->name));
			__debug("|                  \"%s\"", PRINT_NULL(jvm->libjvm_path));
		}
		__debug("+-------------------------------------------------------");
	}
	if (strcmp(argv[0], "eucalyptus-cloud") != 0) {
		char *oldpath = getenv("LD_LIBRARY_PATH"), *libf = java_library(args,
				data);
		char *old = argv[0], buf[32768], *tmp = NULL, *p1 = NULL, *p2 = NULL;
		p1 = strdup(libf);
		tmp = strrchr(p1, '/');
		if (tmp != NULL)
			tmp[0] = '\0';
		p2 = strdup(p1);
		tmp = strrchr(p2, '/');
		if (tmp != NULL)
			tmp[0] = '\0';
		if (oldpath == NULL)
			snprintf(buf, 32768, "%s:%s:%s/bin/linux-x64", p1, p2, GETARG(args,
					profiler_home));
		else
			snprintf(buf, 32768, "%s:%s:%s:%s/bin/linux-x64", oldpath, p1, p2,
					GETARG(args, profiler_home));
		tmp = strdup(buf);

		setenv("LD_LIBRARY_PATH", tmp, 1);
		__debug("Invoking w/ LD_LIBRARY_PATH=%s", getenv("LD_LIBRARY_PATH"));
		argv[0] = "eucalyptus-cloud";
		execve(old, argv, environ);
		__error("Cannot execute process");
		return 1;
	}
	__debug("Running w/ LD_LIBRARY_PATH=%s", getenv("LD_LIBRARY_PATH"));
	if (args->fork_flag) {
		pid = fork();
		__die((pid == -1), "Cannot detach from parent process");
		if (pid != 0)
			return wait_child(args, pid);
		setsid();
	}
	while ((pid = fork()) != -1) {
		if (pid == 0)
			exit(child(args, data, uid, gid));
		child_pid = pid;
		signal(SIGHUP, controller);
		signal(SIGTERM, controller);
		signal(SIGINT, controller);

		while (waitpid(-1, &status, 0) != pid)
			;
		if (WIFEXITED(status)) {
			status = WEXITSTATUS(status);
			__debug("Eucalyptus exited with status: %d", status);
			unlink(GETARG(args, pidfile));
			if (status == EUCA_RET_RELOAD) {
				__debug("Reloading service.");
				continue;
			} else if (status == 0) {
				__debug("Service shut down cleanly.");
				return 0;
			}
			__error("Service exit with a return value of %d.", status);
			return 1;
		} else {
			perror("Service did not exit cleanly.");
			__error("Service did not exit cleanly: exit value=%d.", status);
			return 1;
		}
	}
	__error("Cannot decouple controller/child processes");
	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;
}
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;
}
void euca_load_bootstrapper(void) {
    __die((bootstrap.class_name=((*env)->NewStringUTF(env,EUCA_MAIN)))==NULL,"Cannot create string for class name.");
    __die((bootstrap.clazz=((*env)->FindClass(env,EUCA_MAIN)))==NULL,"Cannot find Eucalyptus bootstrapper: %s.",EUCA_MAIN);
    __debug("Found Eucalyptus bootstrapper: %s",EUCA_MAIN);
    __die((bootstrap.class_ref = (*env)->NewGlobalRef(env, bootstrap.clazz))==NULL,"Cannot create global ref for %s.",EUCA_MAIN);

    JNINativeMethod shutdown_method = { "shutdown","(Z)V",shutdown };
    __die((*env)->RegisterNatives(env,bootstrap.clazz,&shutdown_method,1)!=0,"Cannot register native method: shutdown.");
    JNINativeMethod hello_method = { "hello","()V",hello };
    __die((*env)->RegisterNatives(env,bootstrap.clazz,&hello_method,1)!=0,"Cannot register native method: hello.");
    __debug("Native methods registered.");

    __die((bootstrap.constructor=(*env)->GetStaticMethodID(env, bootstrap.clazz,euca_get_instance.method_name, euca_get_instance.method_signature))==NULL,"Failed to get reference to default constructor.");
    __die((bootstrap.instance=(*env)->CallStaticObjectMethod(env,bootstrap.clazz,bootstrap.constructor))==NULL,"Failed to create instance of bootstrapper.");
    __debug("Created bootstrapper instance.");//TODO: fix all these error messages..
    __die((bootstrap.init=(*env)->GetMethodID(env,bootstrap.clazz,euca_init.method_name,euca_init.method_signature))==NULL,"Failed to get method reference for load.");
    __debug("-> bound method: init");
    __die((bootstrap.load=(*env)->GetMethodID(env,bootstrap.clazz,euca_load.method_name,euca_load.method_signature))==NULL,"Failed to get method reference for load.");
    __debug("-> bound method: load");
    __die((bootstrap.start=(*env)->GetMethodID(env,bootstrap.clazz,euca_start.method_name,euca_start.method_signature))==NULL,"Failed to get method reference for start.");
    __debug("-> bound method: start");
    __die((bootstrap.stop=(*env)->GetMethodID(env,bootstrap.clazz,euca_stop.method_name,euca_stop.method_signature))==NULL,"Failed to get method reference for stop.");
    __debug("-> bound method: stop");
    __die((bootstrap.destroy=(*env)->GetMethodID(env,bootstrap.clazz,euca_destroy.method_name,euca_destroy.method_signature))==NULL,"Failed to get method reference for destroy.");
    __debug("-> bound method: destroy");
    __die((bootstrap.check=(*env)->GetMethodID(env,bootstrap.clazz,euca_check.method_name,euca_check.method_signature))==NULL,"Failed to get method reference for check.");
    __debug("-> bound method: check");
    __die((bootstrap.version=(*env)->GetMethodID(env,bootstrap.clazz,euca_version.method_name,euca_version.method_signature))==NULL,"Failed to get method reference for version.");
    __debug("-> bound method: version");
}
int main( int argc, char *argv[ ] ) {
	euca_opts euca_args;
	euca_opts *args = &euca_args;
	java_home_t *data = NULL;
	int status = 0;
	pid_t pid = 0;
	uid_t uid = 0;
	gid_t gid = 0;
	if( arguments( argc, argv, args ) != 0 ) exit( 1 );
	debug = args->verbose_flag || args->debug_flag;
	if( args->stop_flag == 1 ) return stop_child( args );
	if( checkuser( GETARG( args, user ), &uid, &gid ) == 0 ) return 1;
	char* java_home_user = GETARG(args,java_home);
	char* java_home_env = getenv( "JAVA_HOME" );
	if( java_home_user != NULL ) {
		__debug("Trying user supplied java home: %s", java_home_user);
		data = get_java_home(java_home_user);
	}
	if( data == NULL && java_home_env != NULL ) {
		__debug("Trying environment JAVA_HOME: %s", java_home_env);
		data = get_java_home(java_home_env);
	}
	__debug("TODO: loop through common locations for JVMs here.");
	if( data == NULL ) {
		__error( "Cannot locate Java Home" );
		return 1;
	}
	int x;
	if( debug == 1 ) {
		__debug( "+-- DUMPING JAVA HOME STRUCTURE ------------------------" );
		__debug( "| Java Home:       \"%s\"", PRINT_NULL( data->path ) );
		__debug( "| Found JVMs:      %d", data->jnum );
		for( x = 0; x < data->jnum; x++ ) {
			jvm_info_t *jvm = data->jvms[ x ];
			__debug( "| JVM Name:        \"%s\"", PRINT_NULL( jvm->name ) );
			__debug( "|                  \"%s\"", PRINT_NULL( jvm->libjvm_path ) );
		}
		__debug( "+-------------------------------------------------------" );
	}
	if( strcmp( argv[ 0 ], "eucalyptus-cloud" ) != 0 ) {
		char *oldpath = getenv( "LD_LIBRARY_PATH" ),*libf = java_library( args, data );
		char *old = argv[ 0 ],buf[ 32768 ],*tmp = NULL,*p1 = NULL,*p2 = NULL;
		p1 = strdup( libf );
		tmp = strrchr( p1, '/' );
		if( tmp != NULL ) tmp[ 0 ] = '\0';
		p2 = strdup( p1 );
		tmp = strrchr( p2, '/' );
		if( tmp != NULL ) tmp[ 0 ] = '\0';
		if( oldpath == NULL ) snprintf( buf, 32768, "%s:%s:%s/bin/linux-x64", p1, p2, GETARG(args,profiler_home) );
		else snprintf( buf, 32768, "%s:%s:%s:%s/bin/linux-x64", oldpath, p1, p2, GETARG(args,profiler_home) );
		tmp = strdup( buf );

		setenv( "LD_LIBRARY_PATH", tmp, 1 );
		__debug( "Invoking w/ LD_LIBRARY_PATH=%s", getenv( "LD_LIBRARY_PATH" ) );
		argv[ 0 ] = "eucalyptus-cloud";
		execve( old, argv, environ );
		__error( "Cannot execute process" );
		return 1;
	}
	__debug( "Running w/ LD_LIBRARY_PATH=%s", getenv( "LD_LIBRARY_PATH" ) );
	if(args->fork_flag) {
		pid = fork( );
		__die(( pid == -1 ),"Cannot detach from parent process" );
		if( pid != 0 ) return wait_child( args, pid );
		setsid( );
	}
	set_output(GETARG(args,out), GETARG(args,err));
	while( ( pid = fork( ) ) != -1 ) {
		if( pid == 0 ) exit( child( args, data, uid, gid ) );
		child_pid = pid;
		signal( SIGHUP, controller );
		signal( SIGTERM, controller );
		signal( SIGINT, controller );
		while( waitpid( pid, &status, 0 ) != pid );
		if( WIFEXITED( status ) ) {
			status = WEXITSTATUS( status );
			__debug( "Eucalyptus exited with status: %d", status );
			if( status != 122 ) unlink( GETARG( args, pidfile ) );
			if( status == 123 ) {
				__debug( "Reloading service" );
				continue;
			}
			if( status == 0 ) {
				__debug( "Service shut down" );
				return 0;
			}
			__error( "Service exit with a return value of %d", status );
			return 1;
		} else {
			__error( "Service did not exit cleanly exit value %d", status );
			return 1;
		}
	}
	__error( "Cannot decouple controller/child processes" );
	return 1;
}
Ejemplo n.º 22
0
void __die_if_kernel(const char *str, struct pt_regs *regs,
		const char *file, const char *func, unsigned long line)
{
	if (!user_mode(regs))
		__die(str, regs, file, func, line);
}
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;
}