|
|
139d2d |
From 769c210a4e9494757456c2896fdf67e2eb4b76c1 Mon Sep 17 00:00:00 2001
|
|
|
139d2d |
From: Ken Gaillot <kgaillot@redhat.com>
|
|
|
139d2d |
Date: Fri, 9 Jun 2017 10:49:07 -0500
|
|
|
139d2d |
Subject: [PATCH] Refactor: libcrmcommon,cib,lrmd: functionize allocating IPC
|
|
|
139d2d |
client object
|
|
|
139d2d |
|
|
|
139d2d |
reduces duplication
|
|
|
139d2d |
---
|
|
|
139d2d |
cib/remote.c | 6 +-----
|
|
|
139d2d |
include/crm/common/ipcs.h | 1 +
|
|
|
139d2d |
lib/common/ipc.c | 25 +++++++++++++++++++------
|
|
|
139d2d |
lrmd/tls_backend.c | 5 +----
|
|
|
139d2d |
4 files changed, 22 insertions(+), 15 deletions(-)
|
|
|
139d2d |
|
|
|
139d2d |
diff --git a/cib/remote.c b/cib/remote.c
|
|
|
139d2d |
index 9011552..0160c7e 100644
|
|
|
139d2d |
--- a/cib/remote.c
|
|
|
139d2d |
+++ b/cib/remote.c
|
|
|
139d2d |
@@ -325,13 +325,9 @@ cib_remote_listen(gpointer data)
|
|
|
139d2d |
num_clients++;
|
|
|
139d2d |
|
|
|
139d2d |
crm_client_init();
|
|
|
139d2d |
- new_client = calloc(1, sizeof(crm_client_t));
|
|
|
139d2d |
+ new_client = crm_client_alloc(NULL);
|
|
|
139d2d |
new_client->remote = calloc(1, sizeof(crm_remote_t));
|
|
|
139d2d |
|
|
|
139d2d |
- new_client->id = crm_generate_uuid();
|
|
|
139d2d |
-
|
|
|
139d2d |
- g_hash_table_insert(client_connections, new_client->id /* Should work */ , new_client);
|
|
|
139d2d |
-
|
|
|
139d2d |
if (ssock == remote_tls_fd) {
|
|
|
139d2d |
#ifdef HAVE_GNUTLS_GNUTLS_H
|
|
|
139d2d |
new_client->kind = CRM_CLIENT_TLS;
|
|
|
139d2d |
diff --git a/include/crm/common/ipcs.h b/include/crm/common/ipcs.h
|
|
|
139d2d |
index ba1ccef..06cade9 100644
|
|
|
139d2d |
--- a/include/crm/common/ipcs.h
|
|
|
139d2d |
+++ b/include/crm/common/ipcs.h
|
|
|
139d2d |
@@ -105,6 +105,7 @@ crm_client_t *crm_client_get(qb_ipcs_connection_t * c);
|
|
|
139d2d |
crm_client_t *crm_client_get_by_id(const char *id);
|
|
|
139d2d |
const char *crm_client_name(crm_client_t * c);
|
|
|
139d2d |
|
|
|
139d2d |
+crm_client_t *crm_client_alloc(void *key);
|
|
|
139d2d |
crm_client_t *crm_client_new(qb_ipcs_connection_t * c, uid_t uid, gid_t gid);
|
|
|
139d2d |
void crm_client_destroy(crm_client_t * c);
|
|
|
139d2d |
void crm_client_disconnect_all(qb_ipcs_service_t *s);
|
|
|
139d2d |
diff --git a/lib/common/ipc.c b/lib/common/ipc.c
|
|
|
139d2d |
index d32e373..efe6480 100644
|
|
|
139d2d |
--- a/lib/common/ipc.c
|
|
|
139d2d |
+++ b/lib/common/ipc.c
|
|
|
139d2d |
@@ -293,6 +293,24 @@ crm_client_disconnect_all(qb_ipcs_service_t *service)
|
|
|
139d2d |
}
|
|
|
139d2d |
}
|
|
|
139d2d |
|
|
|
139d2d |
+/*!
|
|
|
139d2d |
+ * \brief Allocate a new crm_client_t object and generate its ID
|
|
|
139d2d |
+ *
|
|
|
139d2d |
+ * \param[in] key What to use as connections hash table key (NULL to use ID)
|
|
|
139d2d |
+ *
|
|
|
139d2d |
+ * \return Pointer to new crm_client_t (asserts on failure)
|
|
|
139d2d |
+ */
|
|
|
139d2d |
+crm_client_t *
|
|
|
139d2d |
+crm_client_alloc(void *key)
|
|
|
139d2d |
+{
|
|
|
139d2d |
+ crm_client_t *client = calloc(1, sizeof(crm_client_t));
|
|
|
139d2d |
+
|
|
|
139d2d |
+ CRM_ASSERT(client != NULL);
|
|
|
139d2d |
+ client->id = crm_generate_uuid();
|
|
|
139d2d |
+ g_hash_table_insert(client_connections, (key? key : client->id), client);
|
|
|
139d2d |
+ return client;
|
|
|
139d2d |
+}
|
|
|
139d2d |
+
|
|
|
139d2d |
crm_client_t *
|
|
|
139d2d |
crm_client_new(qb_ipcs_connection_t * c, uid_t uid_client, gid_t gid_client)
|
|
|
139d2d |
{
|
|
|
139d2d |
@@ -324,21 +342,16 @@ crm_client_new(qb_ipcs_connection_t * c, uid_t uid_client, gid_t gid_client)
|
|
|
139d2d |
crm_client_init();
|
|
|
139d2d |
|
|
|
139d2d |
/* TODO: Do our own auth checking, return NULL if unauthorized */
|
|
|
139d2d |
- client = calloc(1, sizeof(crm_client_t));
|
|
|
139d2d |
-
|
|
|
139d2d |
+ client = crm_client_alloc(c);
|
|
|
139d2d |
client->ipcs = c;
|
|
|
139d2d |
client->kind = CRM_CLIENT_IPC;
|
|
|
139d2d |
client->pid = crm_ipcs_client_pid(c);
|
|
|
139d2d |
|
|
|
139d2d |
- client->id = crm_generate_uuid();
|
|
|
139d2d |
-
|
|
|
139d2d |
crm_debug("Connecting %p for uid=%d gid=%d pid=%u id=%s", c, uid_client, gid_client, client->pid, client->id);
|
|
|
139d2d |
|
|
|
139d2d |
#if ENABLE_ACL
|
|
|
139d2d |
client->user = uid2username(uid_client);
|
|
|
139d2d |
#endif
|
|
|
139d2d |
-
|
|
|
139d2d |
- g_hash_table_insert(client_connections, c, client);
|
|
|
139d2d |
return client;
|
|
|
139d2d |
}
|
|
|
139d2d |
|
|
|
139d2d |
diff --git a/lrmd/tls_backend.c b/lrmd/tls_backend.c
|
|
|
139d2d |
index 8c36434..7d790cf 100644
|
|
|
139d2d |
--- a/lrmd/tls_backend.c
|
|
|
139d2d |
+++ b/lrmd/tls_backend.c
|
|
|
139d2d |
@@ -212,11 +212,10 @@ lrmd_remote_listen(gpointer data)
|
|
|
139d2d |
return TRUE;
|
|
|
139d2d |
}
|
|
|
139d2d |
|
|
|
139d2d |
- new_client = calloc(1, sizeof(crm_client_t));
|
|
|
139d2d |
+ new_client = crm_client_alloc(NULL);
|
|
|
139d2d |
new_client->remote = calloc(1, sizeof(crm_remote_t));
|
|
|
139d2d |
new_client->kind = CRM_CLIENT_TLS;
|
|
|
139d2d |
new_client->remote->tls_session = session;
|
|
|
139d2d |
- new_client->id = crm_generate_uuid();
|
|
|
139d2d |
new_client->remote->auth_timeout =
|
|
|
139d2d |
g_timeout_add(LRMD_REMOTE_AUTH_TIMEOUT, lrmd_auth_timeout_cb, new_client);
|
|
|
139d2d |
crm_notice("LRMD client connection established. %p id: %s", new_client, new_client->id);
|
|
|
139d2d |
@@ -224,8 +223,6 @@ lrmd_remote_listen(gpointer data)
|
|
|
139d2d |
new_client->remote->source =
|
|
|
139d2d |
mainloop_add_fd("lrmd-remote-client", G_PRIORITY_DEFAULT, csock, new_client,
|
|
|
139d2d |
&lrmd_remote_fd_cb);
|
|
|
139d2d |
- g_hash_table_insert(client_connections, new_client->id, new_client);
|
|
|
139d2d |
-
|
|
|
139d2d |
return TRUE;
|
|
|
139d2d |
}
|
|
|
139d2d |
|
|
|
139d2d |
--
|
|
|
139d2d |
1.8.3.1
|
|
|
139d2d |
|