示例#1
0
/**
 * Starts up the rig client by creating a JVM in a seperate thread.
 * Installs a signal handler so a SIGINT or SIGTERM causes the rig
 * client to shut down. */
int main(int argc, char *argv[])
{
	pthread_t thread;
	int code;
	
	struct sigaction shutAction;

	if (!loadConfig())
	{
		logMessage("Failed to load configuration, exiting...\n\n");
		printf("Failed to load configuration, exiting...\n\n");
		return 1;
	}
	
	if (!generateClassPath())
	{
		logMessage("Failed to detected current directory...\n\n");
		printf("Failed to detected current directory...\n\n");
		return 2;
	}

	/* Install signal handler for SIGINT & SIGTERM. */
	shutAction.sa_handler = shutDownSchedulingServer;
	sigemptyset(&shutAction.sa_mask);
	shutAction.sa_flags = SA_RESTART;
	if (sigaction(SIGINT, &shutAction, NULL) == -1)
	{
		logMessage("Unable to install interrupt signal (SIGINT) handler.");
		perror("Failed installing SIGINT handler");
	}
	if (sigaction(SIGTERM, &shutAction, 0) == -1)
	{
		logMessage("Unable to install terminate signal (SIGTERM) handler.");
		perror("Failed installing SIGTERM handler");
	}

	/* Start thread. */
	if (code = pthread_create(&thread, NULL, runSchedulingServer, NULL))
	{
		logMessage("Failed to create JVM thread with code %i.\n", code);
		printf("Failed to create JVM thread with code %i.\n", code);
		return 3;
	}

	pthread_join(thread, NULL);
	return 0;
}
DWORD WINAPI threadMain(LPVOID lpParam)
{
	if (!loadConfig())
    {
		logMessage("ERROR: Unable to load configuration.\n");
		return 0;
    }

	if (!generateClassPath())
	{
		logMessage("ERROR: Unable to generate classpath.\n");
		return 0;
	}
	
	startJVM();
	return 1;
}