Esempio n. 1
0
int interval_from_str(char *str, int d, int p, lng *val)
{
	int sk = digits2sk(d);
	int ek = digits2ek(d);
	*val = 0;
	return parse_interval(NULL, 1, str, sk, ek, p, p, val);
}
Esempio n. 2
0
int do_interval(int *dest, int argc, char **argv)
{
	if (argc < 2)
		return -1;
		
	*dest = parse_interval(argv[1]);
	return 0;
}
Esempio n. 3
0
static int init(int argc, char **argv, struct animation *banner)
{
	int i;
	struct string_list *filenames = NULL, *filenames_tail = NULL;
	int filenames_count = 0;

	init_log();

	i = get_options(argc, argv);
	if (i < 0)
		return usage(argv[0], NULL);

	for ( ; i < argc; ++i) {
		if (banner->interval == (unsigned int)-1)
			if (!parse_interval(argv[i], &banner->interval))
				continue;

		filenames_tail = string_list_add(&filenames, filenames_tail,
				argv[i]);
		if (!filenames_tail)
			return 1;
		else
			filenames_count++;
	}

	if (!filenames_count)
		return usage(argv[0], "No filenames specified");

	if (fb_init(&_Fb))
		return 1;
	if (init_proper_exit())
		return 1;
	if (animation_init(filenames, filenames_count, &_Fb, banner))
		return 1;
	string_list_destroy(filenames);

	if (banner->frame_count == 1 && RunCount == 1)
		banner->interval = 0; /* Single frame, exit after showing it */
	else if (banner->interval == (unsigned int)-1)
		banner->interval = 1000 / 24; /* 24fps */

	if (!Interactive && daemonify())
		ERR_RET(1, "could not create a daemon");

	return 0;
}
Esempio n. 4
0
int
main(int argc, char **argv)
{
	int create_tap = 1;
	int num_tests;
	int ret  = 0;
	int j    = 0;
	int k    = -1;
	int list = 0;
	int opt;
	int i;

#ifdef __FreeBSD__
	PLAIN_REQUIRE_KERNEL_MODULE("if_tap", 0);
	PLAIN_REQUIRE_KERNEL_MODULE("netmap", 0);
#endif

	memset(&ctx_, 0, sizeof(ctx_));

	{
		struct timespec t;
		int idx;

		clock_gettime(CLOCK_REALTIME, &t);
		srand((unsigned int)t.tv_nsec);
		idx = rand() % 8000 + 100;
		snprintf(ctx_.ifname, sizeof(ctx_.ifname), "tap%d", idx);
		idx = rand() % 800 + 100;
		snprintf(ctx_.bdgname, sizeof(ctx_.bdgname), "vale%d", idx);
	}

	while ((opt = getopt(argc, argv, "hi:j:l")) != -1) {
		switch (opt) {
		case 'h':
			usage(argv[0]);
			return 0;

		case 'i':
			strncpy(ctx_.ifname, optarg, sizeof(ctx_.ifname) - 1);
			create_tap = 0;
			break;

		case 'j':
			if (parse_interval(optarg, &j, &k) < 0) {
				usage(argv[0]);
				return -1;
			}
			break;

		case 'l':
			list = 1;
			create_tap = 0;
			break;

		default:
			printf("    Unrecognized option %c\n", opt);
			usage(argv[0]);
			return -1;
		}
	}

	num_tests = sizeof(tests) / sizeof(tests[0]);

	if (j < 0 || j >= num_tests || k > num_tests) {
		fprintf(stderr, "Test interval %d-%d out of range (%d-%d)\n",
				j + 1, k, 1, num_tests + 1);
		return -1;
	}

	if (k < 0)
		k = num_tests;

	if (list) {
		printf("Available tests:\n");
		for (i = 0; i < num_tests; i++) {
			printf("#%03d: %s\n", i + 1, tests[i].name);
		}
		return 0;
	}

	if (create_tap) {
		struct sigaction sa;
		const char *av[8];
		int ac = 0;
#ifdef __FreeBSD__
		ARGV_APPEND(av, ac, "ifconfig");
		ARGV_APPEND(av, ac, ctx_.ifname);
		ARGV_APPEND(av, ac, "create");
		ARGV_APPEND(av, ac, "up");
#else
		ARGV_APPEND(av, ac, "ip");
		ARGV_APPEND(av, ac, "tuntap");
		ARGV_APPEND(av, ac, "add");
		ARGV_APPEND(av, ac, "mode");
		ARGV_APPEND(av, ac, "tap");
		ARGV_APPEND(av, ac, "name");
		ARGV_APPEND(av, ac, ctx_.ifname);
#endif
		ARGV_APPEND(av, ac, NULL);
		if (exec_command(ac, av)) {
			printf("Failed to create tap interface\n");
			return -1;
		}

		sa.sa_handler = tap_cleanup;
		sigemptyset(&sa.sa_mask);
		sa.sa_flags = SA_RESTART;
		ret         = sigaction(SIGINT, &sa, NULL);
		if (ret) {
			perror("sigaction(SIGINT)");
			goto out;
		}
		ret = sigaction(SIGTERM, &sa, NULL);
		if (ret) {
			perror("sigaction(SIGTERM)");
			goto out;
		}
	}

	for (i = j; i < k; i++) {
		struct TestContext ctxcopy;
		int fd;
		printf("==> Start of Test #%d [%s]\n", i + 1, tests[i].name);
		fd = open("/dev/netmap", O_RDWR);
		if (fd < 0) {
			perror("open(/dev/netmap)");
			ret = fd;
			goto out;
		}
		memcpy(&ctxcopy, &ctx_, sizeof(ctxcopy));
		ctxcopy.fd = fd;
		memcpy(ctxcopy.ifname_ext, ctxcopy.ifname,
			sizeof(ctxcopy.ifname));
		ret        = tests[i].test(&ctxcopy);
		if (ret != 0) {
			printf("Test #%d [%s] failed\n", i + 1, tests[i].name);
			goto out;
		}
		printf("==> Test #%d [%s] successful\n", i + 1, tests[i].name);
		context_cleanup(&ctxcopy);
	}
out:
	tap_cleanup(0);

	return ret;
}
Esempio n. 5
0
	void scheduler::add_task(schedule_metadata::task_source source, std::string interval) {
		unsigned int id = tasks.add_task("internal", parse_interval(interval));
		schedule_metadata data;
		data.source = source;
		metadata[id] = data;
	}
Esempio n. 6
0
int main(int argc, char *argv[]) {
	bool foreground = false;
	const char *hostname = NULL;
	const char *port = "2342";
	int interval = 5 * 60;
	int c;

	if(argc > 0) cmd = argv[0];

	if(argc > 1) {
		if(strcmp(argv[1], "--help") == 0) {
			help();
		}
		else if(strcmp(argv[1], "--version") == 0) {
			version();
		}
	}

	while((c = getopt(argc, argv, ":fi:p:")) != -1) {
		switch(c) {
			case 'f':
				foreground = true;
				break;
			case 'i':
				interval = parse_interval(optarg);
				if(interval < 1) {
					fprintf(stderr, "%s: %s: -i\n", cmd, strerror(errno));
					exit(EXIT_FAILURE);
				}
				break;
			case 'p':
				port = optarg;
				break;
			case '?':
				fprintf(stderr, "%s: Invalid option: -%c\n", cmd, optopt);
				exit(EXIT_FAILURE);
			case ':':
				fprintf(stderr, "%s: Option requires an argument: -%c\n", cmd, optopt);
				exit(EXIT_FAILURE);
		}
	}

	if(optind < argc) {
		hostname = argv[optind];
		optind++;
	}
	else {
		fprintf(stderr, "%s: Hostname not specified\n", cmd);
		exit(EXIT_FAILURE);
	}

	if(argc - optind > ARGUMENT_MAX) {
		fprintf(stderr, "%s: Too many arguments\n", cmd);
		exit(EXIT_FAILURE);
	}

	for(; optind < argc; optind++) {
		if(add_argument(argv[optind]) == false) {
			fprintf(stderr, "%s: Buffer size exceeded\n", cmd);
			exit(EXIT_FAILURE);
		}
	}

	client(hostname, port, foreground, interval);

	return EXIT_SUCCESS;
}