File bsc#1137835-0002-ipc-fixes.patch of Package libqb.11706

From 7cd7b06d52ac80c343f362c7e39ef75495439dfc Mon Sep 17 00:00:00 2001
From: Christine Caulfield <ccaulfie@redhat.com>
Date: Tue, 12 Mar 2019 14:08:47 +0000
Subject: [PATCH 2/2] ipc: fixes

Use O_EXCL on IPC files
---
 lib/ipc_setup.c    | 14 ++------------
 lib/ipcs.c         | 14 --------------
 lib/log_blackbox.c |  2 +-
 3 files changed, 3 insertions(+), 27 deletions(-)

diff --git a/lib/ipc_setup.c b/lib/ipc_setup.c
index 36ae2cf..0e16964 100644
--- a/lib/ipc_setup.c
+++ b/lib/ipc_setup.c
@@ -43,9 +43,6 @@
 #include "util_int.h"
 #include "ipc_int.h"
 
-/* Maximum number of times we generate a random socket name before giving up */
-#define MAX_NAME_RETRY_COUNT 20
-
 struct ipc_auth_ugp {
 	uid_t uid;
 	gid_t gid;
@@ -622,7 +619,6 @@ handle_new_connection(struct qb_ipcs_service *s,
 	struct qb_ipc_connection_request *req = msg;
 	int32_t res = auth_result;
 	int32_t res2 = 0;
-	uint32_t retry_count = 0;
 	uint32_t max_buffer_size = QB_MAX(req->max_msg_size, s->max_buffer_size);
 	struct qb_ipc_connection_response response;
 
@@ -647,6 +643,8 @@ handle_new_connection(struct qb_ipcs_service *s,
 	c->auth.gid = c->egid = ugp->gid;
 	c->auth.mode = 0600;
 	c->stats.client_pid = ugp->pid;
+	snprintf(c->description, CONNECTION_DESCRIPTION,
+		 "%d-%d-%d", s->pid, ugp->pid, c->setup.u.us.sock);
 
 	if (auth_result == 0 && c->service->serv_fns.connection_accept) {
 		res = c->service->serv_fns.connection_accept(c,
@@ -659,17 +657,9 @@ handle_new_connection(struct qb_ipcs_service *s,
 	qb_util_log(LOG_DEBUG, "IPC credentials authenticated (%s)",
 		    c->description);
 
-retry_description:
-	snprintf(c->description, CONNECTION_DESCRIPTION,
-		 "%d-%d-%lu", s->pid, ugp->pid, (unsigned long)(random()%65536));
-
 	memset(&response, 0, sizeof(response));
 	if (s->funcs.connect) {
 		res = s->funcs.connect(s, c, &response);
-		if (res == -EEXIST && ++retry_count < MAX_NAME_RETRY_COUNT) {
-			qb_util_log(LOG_DEBUG, "Retrying socket name %s (count=%ld)\n", c->description, retry_count);
-			goto retry_description;
-		}
 		if (res != 0) {
 			goto send_response;
 		}
diff --git a/lib/ipcs.c b/lib/ipcs.c
index 573b427..4a375fc 100644
--- a/lib/ipcs.c
+++ b/lib/ipcs.c
@@ -40,8 +40,6 @@ qb_ipcs_create(const char *name,
 	       enum qb_ipc_type type, struct qb_ipcs_service_handlers *handlers)
 {
 	struct qb_ipcs_service *s;
-	int fd;
-	unsigned int seed;
 
 	s = calloc(1, sizeof(struct qb_ipcs_service));
 	if (s == NULL) {
@@ -77,18 +75,6 @@ qb_ipcs_create(const char *name,
 	qb_list_init(&s->list);
 	qb_list_add(&s->list, &qb_ipc_services);
 
-	/* Randomise socket names */
-	fd = open("/dev/urandom", O_RDONLY);
-	if (fd == -1) {
-		seed = (time_t)time(NULL);
-	} else {
-		if (read(fd, &seed, sizeof(seed)) != 4) {
-			seed = (time_t)time(NULL);
-		}
-		close(fd);
-	}
-	srand(seed);
-
 	return s;
 }
 
diff --git a/lib/log_blackbox.c b/lib/log_blackbox.c
index 2947162..1cba422 100644
--- a/lib/log_blackbox.c
+++ b/lib/log_blackbox.c
@@ -188,7 +188,7 @@ qb_log_blackbox_write_to_file(const char *filename)
 	ssize_t written_size = 0;
 	struct qb_log_target *t;
 	struct _blackbox_file_header header;
-	int fd = open(filename, O_CREAT | O_RDWR | O_EXCL, 0700);
+	int fd = open(filename, O_CREAT | O_RDWR, 0700);
 
 	if (fd < 0) {
 		return -errno;
-- 
2.16.4