Exemple #1
0
int main(int argc, char *argv[])
{
	int opt;
	uint8_t quiet = 0;
	uint8_t daemon = 0;
	config_t cfg;
	ctrler_cfg = calloc(1, sizeof(struct ctrler_cfg));

	signal(SIGINT, int_handler);

	while ((opt = getopt(argc, argv, "bdqvh")) != -1) {
		switch (opt) {
		case 'b':
			pki_bootstrap_certs();
			return 0;
		case 'd':
			daemon = 1;
			break;
		case 'q':
			quiet = 1;
			break;
		case 'v':
			fprintf(stdout, "netvirt-ctrler %s\n", NVCTRLER_VERSION);
			return 0;
		default:
		case 'h':
                        fprintf(stdout, "netvirt-ctrler:\n"
					"-b\t\tbootstrap certificates\n"
					"-d\t\tdaemonize\n"
                                        "-q\t\tquiet mode\n"
                                        "-v\t\tshow version\n"
                                        "-h\t\tshow this help\n");
			return 0;
		}
	}

	if (!quiet && !daemon) {
		jlog_init_cb(on_log);
	}

	config_init(&cfg);

	if (parse_config(&cfg, ctrler_cfg)) {
		jlog(L_ERROR, "parse_config failed");
		exit(EXIT_FAILURE);
	}

	if (krypt_init()) {
		jlog(L_ERROR, "krypt_init failed");
		exit(EXIT_FAILURE);
	}

	if (dao_connect(ctrler_cfg)) {
		jlog(L_ERROR, "dao_connect failed");
		exit(EXIT_FAILURE);
	}

	netbus_tcp_init();
	if (netbus_init()) {
		jlog(L_ERROR, "netbus_init failed");
		exit(EXIT_FAILURE);
	}

	if (ctrler_init(ctrler_cfg)) {
		jlog(L_NOTICE, "ctrler_init failed");
		exit(EXIT_FAILURE);
	}

	if (daemon) {
		daemonize();
	}

	while (ctrler_cfg->ctrler_running) {
		sleep(1);
	}

	ctrler_fini();
	netbus_fini();
	config_destroy(&cfg);
	free(ctrler_cfg);

	sleep(1);

	return 0;
}
Exemple #2
0
int main(int argc, char *argv[])
{
	int opt;
	uint8_t quiet = 0;
	config_t cfg;
	switch_cfg = calloc(1, sizeof(struct switch_cfg));

	signal(SIGINT, int_handler);

	while ((opt = getopt(argc, argv, "qvh")) != -1) {
		switch (opt) {
		case 'q':
			quiet = 1;
			break;
		case 'v':
			fprintf(stdout, "netvirt-switch %s\n", NVSWITCH_VERSION);
			return 0;
		default:
		case 'h':
			fprintf(stdout, "netvirt-switch:\n"
					"-q\t\tquiet mode\n"
					"-v\t\tshow version\n"
					"-h\t\tshow this help\n");
			return 0;
		}
	}

	if (!quiet) {
		jlog_init_cb(on_log);
	}

	config_init(&cfg);
	switch_cfg->ctrl_initialized = 0;

	if (config_parse(&cfg, switch_cfg)) {
		jlog(L_ERROR, "config parse failed");
		exit(EXIT_FAILURE);
	}


	if (krypt_init()) {
		jlog(L_ERROR, "krypt_init failed");
		exit(EXIT_FAILURE);
	}

	netbus_tcp_init();
	if (netbus_init()) {
		jlog(L_ERROR, "netbus_init failed");
		exit(EXIT_FAILURE);
	}

	if (ctrl_init(switch_cfg)) {
		jlog(L_ERROR, "ctrl_init failed");
		exit(EXIT_FAILURE);
	}

	/* make sure control is properly initialized before
		accepting connection */
	while (switch_cfg->ctrl_initialized == 0) {
		sleep(1);
	}

	if (switch_init(switch_cfg)) {
		jlog(L_ERROR, "switch_init failed");
		exit(EXIT_FAILURE);
	}

	while (switch_cfg->ctrl_running || switch_cfg->switch_running) {
		sleep(1);
	}

	/* clean up */
	ctrl_fini();
	switch_fini();
	netbus_fini();
	krypt_fini();
	config_destroy(&cfg);
	free(switch_cfg);

	printf("Goodbye netvirt-switch !\n");

	return 0;
}