Beispiel #1
0
int
qdevice_ipc_close(struct qdevice_instance *instance)
{
    int res;

    res = unix_socket_ipc_close(&instance->local_ipc);
    if (res != 0) {
        qdevice_log_err(LOG_WARNING, "Can't close local IPC");
    }

    return (res);
}
Beispiel #2
0
int
qdevice_ipc_init(struct qdevice_instance *instance)
{
    if (unix_socket_ipc_init(&instance->local_ipc,
                             instance->advanced_settings->local_socket_file,
                             instance->advanced_settings->local_socket_backlog,
                             instance->advanced_settings->ipc_max_clients,
                             instance->advanced_settings->ipc_max_receive_size,
                             instance->advanced_settings->ipc_max_send_size) != 0) {
        qdevice_log_err(LOG_ERR, "Can't create unix socket");

        return (-1);
    }

    return (0);
}
Beispiel #3
0
int
main(int argc, char * const argv[])
{
	struct qdevice_instance instance;
	struct qdevice_advanced_settings advanced_settings;
	int foreground;
	int force_debug;
	int lock_file;
	int another_instance_running;

	if (qdevice_advanced_settings_init(&advanced_settings) != 0) {
		errx(1, "Can't alloc memory for advanced settings");
	}

	cli_parse(argc, argv, &foreground, &force_debug, &advanced_settings);

	qdevice_instance_init(&instance, &advanced_settings);

	qdevice_cmap_init(&instance);
	qdevice_log_init(&instance, force_debug);

	/*
	 * Daemonize
	 */
	if (!foreground) {
		utils_tty_detach();
	}

	if ((lock_file = utils_flock(advanced_settings.lock_file, getpid(),
	    &another_instance_running)) == -1) {
		if (another_instance_running) {
			qdevice_log(LOG_ERR, "Another instance is running");
		} else {
			qdevice_log_err(LOG_ERR, "Can't acquire lock");
		}

		exit(1);
	}

	qdevice_log(LOG_DEBUG, "Initializing votequorum");
	qdevice_votequorum_init(&instance);

	qdevice_log(LOG_DEBUG, "Initializing local socket");
	if (qdevice_ipc_init(&instance) != 0) {
		return (1);
	}

	qdevice_log(LOG_DEBUG, "Registering qdevice models");
	qdevice_model_register_all();

	qdevice_log(LOG_DEBUG, "Configuring qdevice");
	if (qdevice_instance_configure_from_cmap(&instance) != 0) {
		return (1);
	}

	qdevice_log(LOG_DEBUG, "Configuring master_wins");
	if (qdevice_votequorum_master_wins(&instance, (advanced_settings.master_wins ==
	    QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_FORCE_ON ? 1 : 0)) != 0) {
		return (1);
	}

	qdevice_log(LOG_DEBUG, "Getting configuration node list");
	if (qdevice_cmap_store_config_node_list(&instance) != 0) {
		return (1);
	}

	qdevice_log(LOG_DEBUG, "Initializing qdevice model");
	if (qdevice_model_init(&instance) != 0) {
		return (1);
	}

	qdevice_log(LOG_DEBUG, "Initializing cmap tracking");
	if (qdevice_cmap_add_track(&instance) != 0) {
		return (1);
	}

	qdevice_log(LOG_DEBUG, "Waiting for ring id");
	if (qdevice_votequorum_wait_for_ring_id(&instance) != 0) {
		return (1);
	}

	global_instance = &instance;
	signal_handlers_register();

	qdevice_log(LOG_DEBUG, "Running qdevice model");
	if (qdevice_model_run(&instance) != 0) {
		return (1);
	}

	qdevice_log(LOG_DEBUG, "Removing cmap tracking");
	if (qdevice_cmap_del_track(&instance) != 0) {
		return (1);
	}

	qdevice_log(LOG_DEBUG, "Destroying qdevice model");
	qdevice_model_destroy(&instance);

	qdevice_ipc_destroy(&instance);

	qdevice_votequorum_destroy(&instance);
	qdevice_cmap_destroy(&instance);
	qdevice_log_close(&instance);
	qdevice_instance_destroy(&instance);
	qdevice_advanced_settings_destroy(&advanced_settings);

	return (0);
}