Example #1
0
qb_ipcs_service_t *
mainloop_add_ipc_server(const char *name, enum qb_ipc_type type,
                        struct qb_ipcs_service_handlers * callbacks)
{
    int rc = 0;
    qb_ipcs_service_t *server = NULL;

    if (gio_map == NULL) {
        gio_map = qb_array_create_2(64, sizeof(struct gio_to_qb_poll), 1);
    }

    crm_client_init();
    server = qb_ipcs_create(name, 0, pick_ipc_type(type), callbacks);

#ifdef HAVE_IPCS_GET_BUFFER_SIZE
    /* All clients should use at least ipc_buffer_max as their buffer size */
    qb_ipcs_enforce_buffer_size(server, crm_ipc_default_buffer_size());
#endif

    qb_ipcs_poll_handlers_set(server, &gio_poll_funcs);

    rc = qb_ipcs_run(server);
    if (rc < 0) {
        crm_err("Could not start %s IPC server: %s (%d)", name, pcmk_strerror(rc), rc);
        return NULL;
    }

    return server;
}
Example #2
0
qb_ipcs_service_t *mainloop_add_ipc_server(
    const char *name, enum qb_ipc_type type, struct qb_ipcs_service_handlers *callbacks) 
{
    int rc = 0;
    qb_ipcs_service_t* server = NULL;

    if(gio_map == NULL) {
        gio_map = qb_array_create_2(64, sizeof(struct gio_to_qb_poll), 1);
    }

    server = qb_ipcs_create(name, 0, pick_ipc_type(type), callbacks);
    qb_ipcs_poll_handlers_set(server, &gio_poll_funcs);

    rc = qb_ipcs_run(server);
    if (rc < 0) {
        crm_err("Could not start %s IPC server: %s (%d)", name, strerror(rc), rc);
        return NULL;
    }

    return server;
}
Example #3
0
int32_t
main(int32_t argc, char *argv[])
{
	const char *options = "mpseugh";
	int32_t opt;
	enum qb_ipc_type ipc_type = QB_IPC_NATIVE;
	struct qb_ipcs_service_handlers sh = {
		.connection_accept = s1_connection_accept_fn,
		.connection_created = s1_connection_created_fn,
		.msg_process = s1_msg_process_fn,
		.connection_destroyed = s1_connection_destroyed_fn,
		.connection_closed = s1_connection_closed_fn,
	};
	struct qb_ipcs_poll_handlers ph = {
		.job_add = my_job_add,
		.dispatch_add = my_dispatch_add,
		.dispatch_mod = my_dispatch_mod,
		.dispatch_del = my_dispatch_del,
	};
#ifdef HAVE_GLIB
	struct qb_ipcs_poll_handlers glib_ph = {
		.job_add = NULL, /* FIXME */
		.dispatch_add = my_g_dispatch_add,
		.dispatch_mod = my_g_dispatch_mod,
		.dispatch_del = my_g_dispatch_del,
	};
#endif /* HAVE_GLIB */

	while ((opt = getopt(argc, argv, options)) != -1) {
		switch (opt) {
		case 'm':
			ipc_type = QB_IPC_SHM;
			break;
		case 'u':
			ipc_type = QB_IPC_SOCKET;
			break;
		case 'g':
			use_glib = QB_TRUE;
			break;
		case 'e':
			use_events = QB_TRUE;
			break;
		case 'h':
		default:
			show_usage(argv[0]);
			exit(0);
			break;
		}
	}
	signal(SIGINT, sigusr1_handler);

	qb_log_init("ipcserver", LOG_USER, LOG_TRACE);
	qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
			  QB_LOG_FILTER_FILE, "*", LOG_TRACE);
	qb_log_format_set(QB_LOG_STDERR, "%f:%l [%p] %b");
	qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);

	s1 = qb_ipcs_create("ipcserver", 0, ipc_type, &sh);
	if (s1 == 0) {
		qb_perror(LOG_ERR, "qb_ipcs_create");
		exit(1);
	}
	if (!use_glib) {
		bms_loop = qb_loop_create();
		qb_ipcs_poll_handlers_set(s1, &ph);
		qb_ipcs_run(s1);
		qb_loop_run(bms_loop);
	} else {
#ifdef HAVE_GLIB
		glib_loop = g_main_loop_new(NULL, FALSE);
		gio_map = qb_array_create_2(16, sizeof(struct gio_to_qb_poll), 1);
		qb_ipcs_poll_handlers_set(s1, &glib_ph);
		qb_ipcs_run(s1);
		g_main_loop_run(glib_loop);
#else
		qb_log(LOG_ERR,
		       "You don't seem to have glib-devel installed.\n");
#endif
	}
	return EXIT_SUCCESS;
}
Example #4
0
File: bms.c Project: fjrti/libqb
int32_t main(int32_t argc, char *argv[])
{
	const char *options = "nevhmpsug";
	int32_t opt;
	int32_t rc;
	enum qb_ipc_type ipc_type = QB_IPC_SHM;
	struct qb_ipcs_service_handlers sh = {
		.connection_accept = s1_connection_accept_fn,
		.connection_created = s1_connection_created_fn,
		.msg_process = s1_msg_process_fn,
		.connection_destroyed = s1_connection_destroyed_fn,
		.connection_closed = s1_connection_closed_fn,
	};
	struct qb_ipcs_poll_handlers ph = {
		.job_add = my_job_add,
		.dispatch_add = my_dispatch_add,
		.dispatch_mod = my_dispatch_mod,
		.dispatch_del = my_dispatch_del,
	};
#ifdef HAVE_GLIB
	struct qb_ipcs_poll_handlers glib_ph = {
		.job_add = NULL, /* FIXME */
		.dispatch_add = my_g_dispatch_add,
		.dispatch_mod = my_g_dispatch_mod,
		.dispatch_del = my_g_dispatch_del,
	};
#endif /* HAVE_GLIB */

	while ((opt = getopt(argc, argv, options)) != -1) {
		switch (opt) {
		case 'm':
			ipc_type = QB_IPC_SHM;
			break;
		case 'u':
			ipc_type = QB_IPC_SOCKET;
			break;
		case 'n':	/* non-blocking */
			blocking = QB_FALSE;
			break;
		case 'e':	/* events */
			events = QB_TRUE;
			break;
		case 'g':
			use_glib = QB_TRUE;
			break;
		case 'v':
			verbose++;
			break;
		case 'h':
		default:
			show_usage(argv[0]);
			exit(0);
			break;
		}
	}
	signal(SIGINT, sigusr1_handler);
	signal(SIGILL, sigusr1_handler);
	signal(SIGTERM, sigusr1_handler);

	qb_log_init("bms", LOG_USER, LOG_EMERG);
	qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
	qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
			  QB_LOG_FILTER_FILE, "*", LOG_INFO + verbose);
	qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);

	if (!use_glib) {
		bms_loop = qb_loop_create();
		s1 = qb_ipcs_create("bm1", 0, ipc_type, &sh);
		if (s1 == 0) {
			qb_perror(LOG_ERR, "qb_ipcs_create");
			exit(1);
		}
		qb_ipcs_poll_handlers_set(s1, &ph);
		rc = qb_ipcs_run(s1);
		if (rc != 0) {
			errno = -rc;
			qb_perror(LOG_ERR, "qb_ipcs_run");
			exit(1);
		}
		qb_loop_run(bms_loop);
	} else {
#ifdef HAVE_GLIB
		glib_loop = g_main_loop_new(NULL, FALSE);

		gio_map = qb_array_create(64, sizeof(struct gio_to_qb_poll));

		s1 = qb_ipcs_create("bm1", 0, ipc_type, &sh);
		if (s1 == 0) {
			qb_perror(LOG_ERR, "qb_ipcs_create");
			exit(1);
		}
		qb_ipcs_poll_handlers_set(s1, &glib_ph);
		rc = qb_ipcs_run(s1);
		if (rc != 0) {
			errno = -rc;
			qb_perror(LOG_ERR, "qb_ipcs_run");
			exit(1);
		}

		g_main_loop_run(glib_loop);
#else
		qb_log(LOG_ERR, "You don't seem to have glib-devel installed.\n");
#endif
	}
	return EXIT_SUCCESS;
}