Esempio n. 1
0
int main(int argc, char **argv) {
    setlinebuf(stdout);
    set_sig_handlers();
    srv_init();
    option_parse(argc, argv);
    srv_serve();
    srv_destroy();
    exit(0);
}
Esempio n. 2
0
/* Sets a server option */
STATIC TEG_STATUS token_set( int fd, char *str )
{
	if( strlen(str)==0 )
		goto error;

	if( option_parse(fd, str) == TEG_STATUS_SUCCESS )
		return TEG_STATUS_SUCCESS;

error:
	net_print(fd,TOKEN_ERROR"="TOKEN_SET"\n");
	return TEG_STATUS_PARSEERROR;
}
Esempio n. 3
0
int main(int argc, char **argv)
{
	int n;
	char **in;
	char *path;

	option_parse(argc, argv);
	agurim_init();

	argc -= optind;
	argv += optind;

	if (argc == 0){
		/* stdin supports re-aggregation format only. */
		if (query.outfmt != REAGGREGATION) 
			usage();
		else
			read_stdin();
	}

again:
	n = argc;
	in = argv;

	while (n > 0) {
		path = *in;
		if (is_dir(path))
			read_dir(path);
		else
			read_file(path);
		++in;
		--n;
	}
	if (inparam.mode == HHH_MAIN_MODE){
		hhh_run();
		if (query.outfmt != REAGGREGATION) {
			/* reset internal parameters for text processing */
			param_set_nextmode();
			/* goto the second pass */
			goto again;
		}
	} else {
		plot_run();
	}
	agurim_finish();

	return (0);
}
Esempio n. 4
0
void test_option_parse_1()
{
	struct opt_style style1[] = {
		{ OPTSTYLE_YES, "-a" }, OPT_STYLE_NULL
	};
	struct opt_style style2[] = {
		{ OPTSTYLE_NO, "-b" }, OPT_STYLE_NULL
	};
	struct opt_style style3[] = {
		{ OPTSTYLE_AFTER, "-c" }, OPT_STYLE_NULL
	};
	struct opt_style style4[] = {
		{ OPTSTYLE_NEXT, "-d" }, OPT_STYLE_NULL
	};
	struct opt_style style5[] = {
		{ OPTSTYLE_SHORT_YES, "e" }, OPT_STYLE_NULL
	};
	struct opt_style style6[] = {
		{ OPTSTYLE_SHORT_NO, "f" }, OPT_STYLE_NULL
	};
	struct opt_type type[] = {
		{ style1 },
		{ style2 },
		{ style3 },
		{ style4 },
		{ style5 },
		{ style6 }, OPT_TYPE_NULL
	};
	struct opt_parsed parsed[6] = { -1 };

	int argc = 6;
	const char *argv[] = {
		"-a", "-b", "-cXYZ", "-d", "ABC", "-ef"
	};

	int res;

	res = option_parse(argc, argv, type, parsed);

	CU_ASSERT_EQUAL(1, parsed[0].yesno);
	CU_ASSERT_EQUAL(0, parsed[1].yesno);
	CU_ASSERT_PTR_EQUAL(argv[2] + 2, parsed[2].ptr);
	CU_ASSERT_PTR_EQUAL(argv[4], parsed[3].ptr);
	CU_ASSERT_EQUAL(1, parsed[4].yesno);
	CU_ASSERT_EQUAL(0, parsed[5].yesno);
	CU_ASSERT_EQUAL(6, res);
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
    option_t opt;
    int arg_used = 0;
    const char *command = NULL;
    const char *argv0 = argv[0];
    FILE *fpi = stdin, *fpo = stdout, *fpe = stderr;

    /* Show the copyright information. */
    fprintf(fpe, APPLICATION_S " " VERSION_S "  " COPYRIGHT_S "\n");
    fprintf(fpe, "\n");

    /* Parse the command-line option. */
    option_init(&opt);
    arg_used = option_parse(++argv, --argc, parse_options, &opt);
    if (arg_used < 0) {
        return 1;
    }

    /* Show the help message if specified. */
    if (opt.help) {
        show_usage(fpo, argv0);
        return 0;
    }

    /* Check whether a command is specified in the command-line. */
    if (argc <= arg_used) {
        fprintf(fpe, "ERROR: No command specified. See help (-h) for the usage.\n");
        return 1;
    }

    /* Execute the command. */
    command = argv[arg_used];
    if (strcmp(command, "learn") == 0) {
        return main_learn(argc-arg_used, argv+arg_used, argv0);
    } else if (strcmp(command, "tag") == 0) {
        return main_tag(argc-arg_used, argv+arg_used, argv0);
    } else if (strcmp(command, "dump") == 0) {
        return main_dump(argc-arg_used, argv+arg_used, argv0);
    } else {
        fprintf(fpe, "ERROR: Unrecognized command (%s) specified.\n", command);    
        return 1;
    }

    return 0;
}
Esempio n. 6
0
int main_dump(int argc, char *argv[], const char *argv0)
{
    int ret = 0, arg_used = 0;
    dump_option_t opt;
    const char *command = argv[0];
    FILE *fpo = stdout, *fpe = stderr;
    crfsuite_model_t *model = NULL;

    /* Parse the command-line option. */
    dump_option_init(&opt);
    arg_used = option_parse(++argv, --argc, parse_dump_options, &opt);
    if (arg_used < 0) {
        ret = 1;
        goto force_exit;
    }

    /* Show the help message for this command if specified. */
    if (opt.help) {
        show_usage(fpo, argv0, command);
        goto force_exit;
    }

    /* Check for the existence of the model file. */
    if (argc <= arg_used) {
        fprintf(fpe, "ERROR: No model specified.\n");
        ret = 1;
        goto force_exit;
    }

    /* Create a model instance corresponding to the model file. */
    if ((ret = crfsuite_create_instance_from_file(argv[arg_used], (void**)&model, FTYPE_NONE))) {
        goto force_exit;
    }

    /* Dump the model. */
    if ((ret = model->dump(model, fpo))) {
        goto force_exit;
    }

force_exit:
    SAFE_RELEASE(model);
    dump_option_finish(&opt);
    return ret;
}
Esempio n. 7
0
int main(int argc, char **argv)
{
	int ch, longindex, ret, port = SD_LISTEN_PORT, io_port = SD_LISTEN_PORT;
	int rc = 1;
	const char *dirp = DEFAULT_OBJECT_DIR, *short_options;
	char *dir, *p, *pid_file = NULL, *bindaddr = NULL, log_path[PATH_MAX],
	     *argp = NULL;
	bool explicit_addr = false;
	bool daemonize = true;
	int32_t nr_vnodes = -1;
	int64_t zone = -1;
	struct cluster_driver *cdrv;
	struct option *long_options;
	const char *http_options = NULL;
	static struct logger_user_info sheep_info;
	struct stat logdir_st;
	enum log_dst_type log_dst_type;

	sys->cinfo.flags |= SD_CLUSTER_FLAG_AUTO_VNODES;
	sys->node_status = SD_NODE_STATUS_INITIALIZATION;

	sys->rthrottling.max_exec_count = 0;
	sys->rthrottling.queue_work_interval = 0;
	sys->rthrottling.throttling = false;

	install_crash_handler(crash_handler);
	signal(SIGPIPE, SIG_IGN);

	install_sighandler(SIGHUP, sighup_handler, false);

	long_options = build_long_options(sheep_options);
	short_options = build_short_options(sheep_options);
	while ((ch = getopt_long(argc, argv, short_options, long_options,
				 &longindex)) >= 0) {
		switch (ch) {
		case 'p':
			port = strtol(optarg, &p, 10);
			if (optarg == p || port < 1 || UINT16_MAX < port
				|| *p != '\0') {
				sd_err("Invalid port number '%s'", optarg);
				exit(1);
			}
			break;
		case 'P':
			pid_file = optarg;
			break;
		case 'r':
			http_options = optarg;
			break;
		case 'l':
			if (option_parse(optarg, ",", log_parsers) < 0)
				exit(1);
			break;
		case 'n':
			sys->nosync = true;
			break;
		case 'y':
			if (!str_to_addr(optarg, sys->this_node.nid.addr)) {
				sd_err("Invalid address: '%s'", optarg);
				exit(1);
			}
			explicit_addr = true;
			break;
		case 'D':
			sys->backend_dio = true;
			break;
		case 'f':
			daemonize = false;
			break;
		case 'g':
			if (nr_vnodes > 0) {
				sd_err("Options '-g' and '-V' can not be both specified");
				exit(1);
			}
			nr_vnodes = 0;
			break;
		case 'z':
			zone = strtol(optarg, &p, 10);
			if (optarg == p || zone < 0 || UINT32_MAX < zone
				|| *p != '\0') {
				sd_err("Invalid zone id '%s': must be "
				       "an integer between 0 and %u", optarg,
				       UINT32_MAX);
				exit(1);
			}
			sys->this_node.zone = zone;
			break;
		case 'u':
			sys->upgrade = true;
			break;
		case 'c':
			sys->cdrv = find_cdrv(optarg);
			if (!sys->cdrv) {
				sd_err("Invalid cluster driver '%s'", optarg);
				fprintf(stderr, "Supported drivers:");
				FOR_EACH_CLUSTER_DRIVER(cdrv) {
					fprintf(stderr, " %s", cdrv->name);
				}
				fprintf(stderr, "\n");
				exit(1);
			}

			sys->cdrv_option = get_cdrv_option(sys->cdrv, optarg);
			break;
		case 'w':
			sys->enable_object_cache = true;
			sys->object_cache_size = 0;

			if (option_parse(optarg, ",", cache_parsers) < 0)
				exit(1);

			if (sys->object_cache_size == 0) {
				sd_err("object cache size is not set");
				exit(1);
			}
			break;
		case 'i':
			if (option_parse(optarg, ",", ionic_parsers) < 0)
				exit(1);

			if (!str_to_addr(io_addr, sys->this_node.nid.io_addr)) {
				sd_err("Bad addr: '%s'", io_addr);
				exit(1);
			}

			if (io_pt)
				if (sscanf(io_pt, "%u", &io_port) != 1) {
					sd_err("Bad port '%s'", io_pt);
					exit(1);
				}
			sys->this_node.nid.io_port = io_port;
			break;
		case 'j':
			uatomic_set_true(&sys->use_journal);
			if (option_parse(optarg, ",", journal_parsers) < 0)
				exit(1);
			if (!jsize) {
				sd_err("you must specify size for journal");
				exit(1);
			}
			break;
		case 'b':
			if (!inetaddr_is_valid(optarg))
				exit(1);
			bindaddr = optarg;
			break;
		case 'h':
			usage(0);
			break;
		case 'R':
			if (option_parse(optarg, ",", recovery_parsers) < 0)
				exit(1);
			sys->rthrottling.max_exec_count = max_exec_count;
			sys->rthrottling.queue_work_interval
						 = queue_work_interval;
			if (max_exec_count > 0 && queue_work_interval > 0)
				sys->rthrottling.throttling = true;
			break;
		case 'v':
			fprintf(stdout, "Sheepdog daemon version %s\n",
				PACKAGE_VERSION);
			exit(0);
			break;
		case 'V':
			sys->cinfo.flags &= ~SD_CLUSTER_FLAG_AUTO_VNODES;
			if (nr_vnodes == 0) {
				sd_err("Options '-g' and '-V' can not be both specified");
				exit(1);
			}
			nr_vnodes = strtol(optarg, &p, 10);
			if (optarg == p || nr_vnodes < 1
				|| UINT16_MAX < nr_vnodes || *p != '\0') {
				sd_err("Invalid number of vnodes '%s': must be "
					"an integer between 1 and %u",
					optarg, UINT16_MAX);
				exit(1);
			}
			break;
		case 'W':
			wildcard_recovery = true;
			break;
		default:
			usage(1);
			break;
		}
	}