Ejemplo n.º 1
0
void add_java_home_to_path(void)
{
	const char *java_home = get_java_home();
	struct string *new_path = string_init(32), *buffer;
	const char *env;

	if (!java_home)
		return;
	buffer = string_initf("%s/bin", java_home);
	if (dir_exists(buffer->buffer))
		string_append_path_list(new_path, buffer->buffer);
	string_setf(buffer, "%s/jre/bin", java_home);
	if (dir_exists(buffer->buffer))
		string_append_path_list(new_path, buffer->buffer);

	env = getenv("PATH");
	string_append_path_list(new_path, env ? env : get_ij_dir());
	setenv_or_exit("PATH", new_path->buffer, 1);
	string_release(buffer);
	string_release(new_path);
}
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.º 3
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;
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{
	int i;
	char cwd[PATH_MAX+1];
	
	if (getcwd(cwd, PATH_MAX+1) == NULL) {
		perror("getcwd failed");
	} else {
		
        char java_exe[PATH_MAX+1];
        char bbwp_path[PATH_MAX+1];
        char bbwp_jar[PATH_MAX+1];
        char new_cwd[PATH_MAX+1];
		int len = strlen(argv[0]);
		int i = len-1;
		while (i>0 && argv[0][i]!='/') i--;
		argv[0][i+1]=0;
		if (argv[0][0] == '/')
		{
			bbwp_jar[0]=0;
		}
		else 
		{
			strncpy(bbwp_jar, cwd,PATH_MAX+1);
			strncat(bbwp_jar, "/",PATH_MAX+1);
		}
		strncat(bbwp_jar, argv[0], PATH_MAX+1);
		strncpy(new_cwd, bbwp_jar, PATH_MAX+1);
		strncat(bbwp_jar, BBWP, PATH_MAX+1);

		struct stat buf;
		int status=0;
		status = stat(bbwp_jar, &buf);
		if (status == 0 && buf.st_mode & S_IFREG == S_IFREG ) 
		{
			strncpy(bbwp_jar, new_cwd, PATH_MAX+1);
			strncpy(bbwp_path, new_cwd, PATH_MAX+1);
			strncat(bbwp_jar, BIN_BBWP_JAR, PATH_MAX+1);			
		}
		else {
			char *tmp = getBBWPjarPath();
			if (tmp == NULL) 
			{
				printf("cannot locate bbwp in path\n");
				return -1;
			}
			strncpy(bbwp_jar,tmp, PATH_MAX+1);
			strncpy(bbwp_path,tmp, PATH_MAX+1);
			free(tmp);
			strncat(bbwp_jar, BIN_BBWP_JAR, PATH_MAX+1);			
		}
        xmlChar * java_home = get_java_home(bbwp_path);
		
        if (java_home){
			strncpy(java_exe, java_home, PATH_MAX+1);
			strncat(java_exe, "/bin/java", PATH_MAX+1);
			
        } else {
			strncpy(java_exe, JAVA, PATH_MAX+1);
        }
        strncpy(java_exe, JAVA, PATH_MAX+1);
		
        char *new_args[argc+3];
		
        new_args[0] = java_exe;
        new_args[1] = "-jar";
        new_args[2] = bbwp_jar;
        for(i = 1; i < argc; i++) {
			new_args[2+i] = argv[i];
        }
        new_args[argc+2] = NULL;
		
        if (execvp(new_args[0], new_args) < 0) {
			printf("execvp failed %s \n",new_args[0]);
        }
	}
	
	return 0;
}
Ejemplo n.º 5
0
const char *get_jre_home(void)
{
	const char *result;
	int len;
	static struct string *jre;
	static int initialized;

	if (jre)
		return jre->buffer;

	if (initialized)
		return NULL;
	initialized = 1;

	/* ImageJ 1.x ships the JRE in <ij.dir>/jre/ */
	result = legacy_jre_path ? legacy_jre_path->buffer : ij_path("jre");
	if (dir_exists(result)) {
		struct string *libjvm = string_initf("%s/%s", result, default_library_path);
		if (!file_exists(libjvm->buffer)) {
			if (debug)
				error("Invalid jre/: '%s' does not exist!",
						libjvm->buffer);
		}
		else if (!is_native_library(libjvm->buffer)) {
			if (debug)
				error("Invalid jre/: '%s' is not a %s library!",
						libjvm->buffer, get_platform());
		}
		else {
			string_release(libjvm);
			jre = string_initf("%s", result);
			if (debug)
				error("JRE found in '%s'", jre->buffer);
			return jre->buffer;
		}
		string_release(libjvm);
	}
	else {
		if (debug)
			error("JRE not found in '%s'", result);
	}

	result = get_java_home();
	if (!result) {
		const char *jre_home = getenv("JRE_HOME");
		if (jre_home && *jre_home && is_jre_home(jre_home)) {
			jre = string_copy(jre_home);
			if (debug)
				error("Found a JRE in JRE_HOME: %s", jre->buffer);
			return jre->buffer;
		}
		jre_home = getenv("JAVA_HOME");
		if (jre_home && *jre_home && is_jre_home(jre_home)) {
			jre = string_copy(jre_home);
			if (debug)
				error("Found a JRE in JAVA_HOME: %s", jre->buffer);
			return jre->buffer;
		}
		if (debug)
			error("No JRE was found in default locations");
		return NULL;
	}

	len = strlen(result);
	if (len > 4 && !suffixcmp(result, len, "/jre")) {
		jre = string_copy(result);
		if (debug)
			error("JAVA_HOME points to a JRE: '%s'", result);
		return jre->buffer;
	}

	jre = string_initf("%s/jre", result);
	if (dir_exists(jre->buffer)) {
		if (debug)
			error("JAVA_HOME contains a JRE: '%s'", jre->buffer);
		return jre->buffer;
	}
	string_set(jre, result);
	if (debug)
		error("JAVA_HOME appears to be a JRE: '%s'", jre->buffer);
	return jre->buffer;
}