コード例 #1
0
int main(int argc, char *argv[])
{
    Display *dpy;
    Bool ret;
    int major, minor;
    int use_gvi = -1;
    int i;
    char *topology_str = NULL;

    /*
     * Open a display connection, and make sure the NV-CONTROL X
     * extension is present on the screen we want to use.
     */
    
    dpy = XOpenDisplay(NULL);
    if (!dpy) {
        printf("Cannot open display '%s'.\n", XDisplayName(NULL));
        return 1;
    }
    
    /* Query the NV-CONTROL version */

    ret = XNVCTRLQueryVersion(dpy, &major, &minor);
    if (ret != True) {
        printf("The NV-CONTROL X extension does not exist on '%s'.\n",
                XDisplayName(NULL));
        return 1;
    }
    
    /* Print some information */

    printf("Using NV-CONTROL extension %d.%d on %s\n\n",
           major, minor, XDisplayName(NULL));

    /* See if user wants a specific GVI device */

    for (i = 0; i < argc; i++) {
        if ((strcmp(argv[i], "-g") == 0) && ((i+1) < argc)) {
            use_gvi = strtol(argv[i+1], NULL, 10);
        }
        if ((strcmp(argv[i], "-c") == 0) && ((i+1) < argc)) {
            topology_str = argv[i+1];
        }
    }
    
    /* Do what the user wants */

    ret = 0;
    for (i = 0; i < argc; i++) {
        if (strcmp(argv[i], "-q") == 0) {
            do_query(dpy, use_gvi);
            ret = 1;
            break;
        } else if (strcmp(argv[i], "-c") == 0) {
            do_configure(dpy, use_gvi, topology_str);
            ret = 1;
            break;
        } else if (strcmp(argv[i], "-l") == 0) {
            do_listconfig(dpy, use_gvi);
            ret = 1;
        }
    }
    if (!ret) {
        do_help();
    }

    return 0;
}
コード例 #2
0
ファイル: main.c プロジェクト: jnpkrn/fence-virt
int
main(int argc, char **argv)
{
	char val[4096];
	char listener_name[80];
	char backend_name[80];
	const char *config_file = DEFAULT_CONFIG_FILE;
	config_object_t *config = NULL;
	map_object_t *map = NULL;
	const listener_plugin_t *lp;
	const backend_plugin_t *p;
	listener_context_t listener_ctx = NULL;
	backend_context_t backend_ctx = NULL;
	int debug_set = 0, foreground = 0, wait_for_init = 0;
	int opt, configure = 0;

	config = sc_init();
	map = map_init();

	if (!config || !map) {
		perror("malloc");
		return -1;
	}

	while ((opt = getopt(argc, argv, "Ff:d:cwlh")) != EOF) {
		switch(opt) {
		case 'F':
			printf("Background mode disabled\n");
			foreground = 1;
			break;
		case 'f':
			printf("Using %s\n", optarg);
			config_file = optarg;
			break;
		case 'd':
			debug_set = atoi(optarg);
			break;
		case 'c':
			configure = 1;
			break;
		case 'w':
			wait_for_init = 1;
			break;
		case 'l':
			plugin_dump();
			return 0;
		case 'h':
		case '?':
			usage();
			return 0;
		default:
			return -1;
		}
	}

	if (configure) {
		return do_configure(config, config_file);
	}

	if (sc_parse(config, config_file) != 0) {
		printf("Failed to parse %s\n", config_file);
		return -1;
	}

	if (debug_set) {
		snprintf(val, sizeof(val), "%d", debug_set);
		sc_set(config, "fence_virtd/@debug", val);
	} else {
		if (sc_get(config, "fence_virtd/@debug", val, sizeof(val))==0)
			debug_set = atoi(val);
	}

	dset(debug_set);

	if (!foreground) {
		if (sc_get(config, "fence_virtd/@foreground",
			   val, sizeof(val)) == 0)
			foreground = atoi(val);
	}

	if (!wait_for_init) {
		if (sc_get(config, "fence_virtd/@wait_for_init",
			   val, sizeof(val)) == 0)
			wait_for_init = atoi(val);
		if (!wait_for_init) {
			/* XXX compat */
			if (sc_get(config, "fence_virtd/@wait_for_backend",
				   val, sizeof(val)) == 0)
				wait_for_init = atoi(val);
		}
	}

	if (dget() > 3)
		sc_dump(config, stdout);

	if (sc_get(config, "fence_virtd/@backend", backend_name,
		   sizeof(backend_name))) {
		printf("Failed to determine backend.\n");
		printf("%s\n", val);
		return -1;
	}

	dbg_printf(1, "Backend plugin: %s\n", backend_name);

	if (sc_get(config, "fence_virtd/@listener", listener_name,
		   sizeof(listener_name))) {
		printf("Failed to determine backend.\n");
		printf("%s\n", val);
		return -1;
	}

	dbg_printf(1, "Listener plugin: %s\n", listener_name);

#ifdef _MODULE
	if (sc_get(config, "fence_virtd/@module_path", val,
		   sizeof(val))) {
#ifdef MODULE_PATH
		snprintf(val, sizeof(val), MODULE_PATH);
#else
		printf("Failed to determine module path.\n");
		return -1;
#endif
	}

	dbg_printf(1, "Searching %s for plugins...\n", val);

	opt = plugin_search(val);
	if (opt > 0) {
		dbg_printf(1, "%d plugins found\n", opt);
	} else {
		printf("No plugins found\n");
		return 1;
	}

#endif
	if (dget() > 3)
		plugin_dump();

	lp = plugin_find_listener(listener_name);
	if (!lp) {
		printf("Could not find listener \"%s\"\n", listener_name);
		return 1;
	}

	p = plugin_find_backend(backend_name);
	if (!p) {
		printf("Could not find backend \"%s\"\n", backend_name);
		return 1;
	}

	daemon_init(basename(argv[0]), foreground);
	signal(SIGINT, exit_handler);
	signal(SIGTERM, exit_handler);
	signal(SIGQUIT, exit_handler);

	syslog(LOG_NOTICE, "fence_virtd starting.  Listener: %s  Backend: %s", backend_name, listener_name);

	while (p->init(&backend_ctx, config) < 0) {
		if (!wait_for_init) {
			if (foreground) {
				printf("Backend plugin %s failed to initialize\n",
				       backend_name);
			}
			syslog(LOG_ERR,
			       "Backend plugin %s failed to initialize\n",
			       backend_name);
			return 1;
		}
		sleep(5);
	}

	if (map_load(map, config) < 0) {
		syslog(LOG_WARNING, "Failed to load static maps\n");
	}

	/* only client we have now is mcast (fence_xvm behavior) */
	while (lp->init(&listener_ctx, p->callbacks, config, map,
			backend_ctx) != 0) {
		if (!wait_for_init) {
			if (foreground) {
				printf("Listener plugin %s failed to initialize\n",
				       listener_name);
			}
			syslog(LOG_ERR,
			       "Listener plugin %s failed to initialize\n",
			       listener_name);
			return 1;
		}
		sleep(5);
	}

	while (run && lp->dispatch(listener_ctx, NULL) >= 0);

	syslog(LOG_NOTICE, "fence_virtd shutting down");

	map_release(map);
	sc_release(config);

	lp->cleanup(listener_ctx);
	p->cleanup(backend_ctx);

	daemon_cleanup();

	return 0;
}
コード例 #3
0
ファイル: main.c プロジェクト: SlySven/tintin
int main(int argc, char **argv)
{
	int greeting = TRUE;

	#ifdef SOCKS
		SOCKSinit(argv[0]);
	#endif

	if (signal(SIGTERM, trap_handler) == BADSIG)
	{
		syserr("signal SIGTERM");
	}

	if (signal(SIGSEGV, trap_handler) == BADSIG)
	{
		syserr("signal SIGSEGV");
	}

	if (signal(SIGHUP, trap_handler) == BADSIG)
	{
		syserr("signal SIGHUP");
	}

	if (signal(SIGABRT, abort_handler) == BADSIG)
	{
		syserr("signal SIGTERM");
	}

	if (signal(SIGINT, abort_handler) == BADSIG)
	{
		syserr("signal SIGINT");
	}

	if (signal(SIGTSTP, suspend_handler) == BADSIG)
	{
		syserr("signal SIGSTOP");
	}

	if (signal(SIGPIPE, pipe_handler) == BADSIG)
	{
		syserr("signal SIGPIPE");
	}

	if (signal(SIGWINCH, winch_handler) == BADSIG)
	{
		syserr("signal SIGWINCH");
	}

/*
	if (getenv("HOME") != NULL)
	{
		char filename[256];

		sprintf(filename, "%s/%s", getenv("HOME"), HISTORY_FILE);

		read_history(gts, filename);
	}
*/

	srand(time(NULL));

	if (argc > 1)
	{
		int c;

		while ((c = getopt(argc, argv, "e: G h r: s: t: v")) != EOF)
		{
			if (c == 'G')
			{
				greeting = FALSE;
			}
		}

		optind = 1;
	}

	init_tintin(greeting);

	if (argc > 1)
	{
		int c;

		optind = 1;

		while ((c = getopt(argc, argv, "e: G h r: s: t: v")) != EOF)
		{
			switch (c)
			{
				case 'e':
					gtd->ses = script_driver(gtd->ses, -1, optarg);
					break;

				case 'G':
					break;

				case 'h':
					tintin_printf(NULL, "Usage: %s [OPTION]... [FILE]...", argv[0]);
					tintin_printf(NULL, "");
					tintin_printf(NULL, "  -e  Execute given command.");
					tintin_printf(NULL, "  -G  Don't show the greeting screen.");
					tintin_printf(NULL, "  -h  This help section.");
					tintin_printf(NULL, "  -r  Read given file.");
					tintin_printf(NULL, "  -t  Set given title.");
					tintin_printf(NULL, "  -v  Enable verbose mode.");

					restore_terminal();
					exit(1);
					break;

				case 'r':
					gtd->ses = do_read(gtd->ses, optarg);
					break;

				case 't':
					printf("\033]0;%s\007", optarg);
					break;

				case 's':
					srand((unsigned int) atoll(optarg));
					break;

				case 'v':
					do_configure(gtd->ses, "{VERBOSE} {ON}");
					break;

				default:
					tintin_printf(NULL, "Unknown option '%c'.", c);
					break;
			}
		}

		if (argv[optind] != NULL)
		{
			gtd->ses = do_read(gtd->ses, argv[optind]);
		}
	}
	check_all_events(gts, SUB_ARG|SUB_SEC, 0, 2, "PROGRAM START", CLIENT_NAME, CLIENT_VERSION);
	check_all_events(gts, SUB_ARG|SUB_SEC, 0, 2, "SCREEN RESIZE", ntos(gts->cols), ntos(gts->rows));

	mainloop();

	return 0;
}
コード例 #4
0
ファイル: main.c プロジェクト: SlySven/tintin
void init_tintin(int greeting)
{
	int ref, index;

	gts = (struct session *) calloc(1, sizeof(struct session));

	for (index = 0 ; index < LIST_MAX ; index++)
	{
		gts->list[index] = init_list(gts, index, 32);
	}

	gts->name           = strdup("gts");
	gts->group          = strdup("");
	gts->host           = strdup("");
	gts->port           = strdup("");
	gts->cmd_color      = strdup("");
	gts->telopts        = TELOPT_FLAG_ECHO;
	gts->flags          = SES_FLAG_MCCP;
	gts->socket         = 1;
	gts->read_max       = 16384;

	gtd                 = (struct tintin_data *) calloc(1, sizeof(struct tintin_data));

	gtd->ses            = gts;

	gtd->str_size       = sizeof(struct str_data);
	gtd->str_hash_size  = sizeof(struct str_hash_data);

	gtd->mccp_len       = 4096;
	gtd->mccp_buf       = (unsigned char *) calloc(1, gtd->mccp_len);

	gtd->mud_output_max = 16384;
	gtd->mud_output_buf = (char *) calloc(1, gtd->mud_output_max);

	gtd->input_off      = 1;

	gtd->term           = strdup(getenv("TERM") ? getenv("TERM") : "UNKNOWN");

	for (index = 0 ; index < 100 ; index++)
	{
		gtd->vars[index] = strdup("");
		gtd->cmds[index] = strdup("");
	}

	for (ref = 0 ; ref < 26 ; ref++)
	{
		for (index = 0 ; *command_table[index].name != 0 ; index++)
		{
			if (*command_table[index].name == 'a' + ref)
			{
				gtd->command_ref[ref] = index;
				break;
			}
		}
	}

	init_screen_size(gts);

	printf("\033="); // set application keypad mode

	gts->input_level++;

	do_configure(gts, "{AUTO TAB}         {5000}");
	do_configure(gts, "{BUFFER SIZE}     {20000}");
	do_configure(gts, "{COLOR PATCH}       {OFF}");
	do_configure(gts, "{COMMAND COLOR}   {<078>}");
	do_configure(gts, "{COMMAND ECHO}       {ON}");
	do_configure(gts, "{CONNECT RETRY}      {15}");
	do_configure(gts, "{CHARSET}         {ASCII}");
	do_configure(gts, "{HISTORY SIZE}     {1000}");
	do_configure(gts, "{LOG}               {RAW}");
	do_configure(gts, "{PACKET PATCH}     {0.00}");
	do_configure(gts, "{REPEAT CHAR}         {!}");
	do_configure(gts, "{REPEAT ENTER}      {OFF}");
	do_configure(gts, "{SCROLL LOCK}        {ON}");
	do_configure(gts, "{SPEEDWALK}         {OFF}");
	do_configure(gts, "{TINTIN CHAR}         {#}");
	do_configure(gts, "{VERBATIM}          {OFF}");
	do_configure(gts, "{VERBATIM CHAR}      {\\}");
	do_configure(gts, "{VERBOSE}           {OFF}");
	do_configure(gts, "{WORDWRAP}           {ON}");
	do_configure(gts, "{256 COLORS}       {AUTO}");

	gts->input_level--;

	insert_node_list(gts->list[LIST_PATHDIR],  "n",  "s",  "1");
	insert_node_list(gts->list[LIST_PATHDIR],  "e",  "w",  "2");
	insert_node_list(gts->list[LIST_PATHDIR],  "s",  "n",  "4");
	insert_node_list(gts->list[LIST_PATHDIR],  "w",  "e",  "8");
	insert_node_list(gts->list[LIST_PATHDIR],  "u",  "d", "16");
	insert_node_list(gts->list[LIST_PATHDIR],  "d",  "u", "32");

	insert_node_list(gts->list[LIST_PATHDIR], "ne", "sw",  "3");
	insert_node_list(gts->list[LIST_PATHDIR], "nw", "se",  "9");
	insert_node_list(gts->list[LIST_PATHDIR], "se", "nw",  "6");
	insert_node_list(gts->list[LIST_PATHDIR], "sw", "ne", "12");

	init_terminal();

	if (greeting)
	{
		do_advertise(gts, "");

		do_help(gts, "GREETING");
	}
}
コード例 #5
0
ファイル: sclp_chp.c プロジェクト: PennPanda/linux-repo
/**
 * sclp_chp_deconfigure - perform deconfigure channel-path sclp command
 * @chpid: channel-path ID
 *
 * Perform deconfigure channel-path command sclp command for specified chpid
 * and wait for completion. On success return 0. Return non-zero otherwise.
 */
int sclp_chp_deconfigure(struct chp_id chpid)
{
	return do_configure(get_deconfigure_cmdw(chpid));
}