コード例 #1
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;
	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;
}
コード例 #2
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;
}
コード例 #3
0
ファイル: eucalyptus-bootstrap.c プロジェクト: sosilent/euca
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;
}
コード例 #4
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=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;
}
コード例 #5
0
ファイル: jsvc-unix.c プロジェクト: utcuong3010/nds
int main(int argc, char *argv[])
{
    arg_data *args  = NULL;
    home_data *data = NULL;
    pid_t pid  = 0;
    uid_t uid  = 0;
    gid_t gid  = 0;
    int res;

    /* Parse command line arguments */
    args = arguments(argc, argv);
    if (args == NULL)
        return 1;

    /* Stop running jsvc if required */
    if (args->stop == true)
        return (stop_child(args));

    /* Let's check if we can switch user/group IDs */
    if (checkuser(args->user, &uid, &gid) == false)
        return 1;

    /* Retrieve JAVA_HOME layout */
    data = home(args->home);
    if (data == NULL)
        return 1;

    /* Check for help */
    if (args->help == true) {
        help(data);
        return 0;
    }

#ifdef OS_LINUX
    /* On some UNIX operating systems, we need to REPLACE this current
       process image with another one (thru execve) to allow the correct
       loading of VMs (notably this is for Linux). Set, replace, and go. */
    if (strcmp(argv[0], args->procname) != 0) {
        char *oldpath = getenv("LD_LIBRARY_PATH");
        char *libf    = java_library(args, data);
        char *filename;
        char  buf[2048];
        int   ret;
        char *tmp = NULL;
        char *p1  = NULL;
        char *p2  = NULL;

        /*
         * There is no need to change LD_LIBRARY_PATH
         * if we were not able to find a path to libjvm.so
         * (additionaly a strdup(NULL) cores dump on my machine).
         */
        if (libf != 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, 2048, "%s:%s", p1, p2);
            else
                snprintf(buf, 2048, "%s:%s:%s", oldpath, p1, p2);

            tmp = strdup(buf);
            setenv("LD_LIBRARY_PATH", tmp, 1);

            log_debug("Invoking w/ LD_LIBRARY_PATH=%s",
                      getenv("LD_LIBRARY_PATH"));
        }

        /* execve needs a full path */
        ret = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
        if (ret <= 0)
            strcpy(buf, argv[0]);
        else
            buf[ret] = '\0';

        filename = buf;

        argv[0] = args->procname;
        execve(filename, argv, environ);
        log_error("Cannot execute JSVC executor process (%s)", filename);
        return 1;
    }
    log_debug("Running w/ LD_LIBRARY_PATH=%s", getenv("LD_LIBRARY_PATH"));
#endif /* ifdef OS_LINUX */

    /* If we have to detach, let's do it now */
    if (args->dtch == true) {
        pid = fork();
        if (pid == -1) {
            log_error("Cannot detach from parent process");
            return 1;
        }
        /* If we're in the parent process */
        if (pid != 0) {
            if (args->wait >= 10)
                return wait_child(args, pid);
            else
                return 0;
        }
#ifndef NO_SETSID
        setsid();
#endif
    }

    /*
     * umask() uses inverse logic; bits are CLEAR for allowed access.
     */
    if (~args->umask & 0022) {
        log_error("NOTICE: jsvc umask of %03o allows "
                  "write permission to group and/or other", args->umask);
    }
    envmask = umask(args->umask);
    set_output(args->outfile, args->errfile, args->redirectstdin, args->procname);
    log_debug("Switching umask back to %03o from %03o", envmask, args->umask);
    res = run_controller(args, data, uid, gid);
    if (logger_pid != 0) {
        kill(logger_pid, SIGTERM);
    }

    return res;
}
コード例 #6
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, 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;
}
コード例 #7
0
ファイル: java.c プロジェクト: Littlegump/CronHub_daemon
/* 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;
}