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;
}
Beispiel #2
0
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_jni((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");
}