Blame SOURCES/0021-udscs-udscs_connect-return-error-to-caller.patch

f8004d
From 09de02fd5cb12fcda3326e243981750c5358b7b6 Mon Sep 17 00:00:00 2001
f8004d
From: Victor Toso <victortoso@redhat.com>
f8004d
Date: Mon, 20 Dec 2021 19:09:37 +0100
f8004d
Subject: [PATCH 21/21] udscs: udscs_connect: return error to caller
f8004d
f8004d
This way we can have the log in one place and avoid flooding the journal.
f8004d
f8004d
Signed-off-by: Victor Toso <victortoso@redhat.com>
f8004d
---
f8004d
 src/udscs.c           | 10 ++++------
f8004d
 src/udscs.h           |  5 ++++-
f8004d
 src/vdagent/vdagent.c | 12 +++++++++---
f8004d
 3 files changed, 17 insertions(+), 10 deletions(-)
f8004d
f8004d
diff --git a/src/udscs.c b/src/udscs.c
f8004d
index 3df67b3..6c50f76 100644
f8004d
--- a/src/udscs.c
f8004d
+++ b/src/udscs.c
f8004d
@@ -107,16 +107,14 @@ static void udscs_connection_class_init(UdscsConnectionClass *klass)
f8004d
 UdscsConnection *udscs_connect(const char *socketname,
f8004d
     udscs_read_callback read_callback,
f8004d
     VDAgentConnErrorCb error_cb,
f8004d
-    int debug)
f8004d
+    int debug,
f8004d
+    GError **err)
f8004d
 {
f8004d
     GIOStream *io_stream;
f8004d
     UdscsConnection *conn;
f8004d
-    GError *err = NULL;
f8004d
 
f8004d
-    io_stream = vdagent_socket_connect(socketname, &err;;
f8004d
-    if (err) {
f8004d
-        syslog(LOG_ERR, "%s: %s", __func__, err->message);
f8004d
-        g_error_free(err);
f8004d
+    io_stream = vdagent_socket_connect(socketname, err);
f8004d
+    if (*err) {
f8004d
         return NULL;
f8004d
     }
f8004d
 
f8004d
diff --git a/src/udscs.h b/src/udscs.h
f8004d
index 4f7ea36..0d4197b 100644
f8004d
--- a/src/udscs.h
f8004d
+++ b/src/udscs.h
f8004d
@@ -53,11 +53,14 @@ typedef void (*udscs_read_callback)(UdscsConnection *conn,
f8004d
  *
f8004d
  * If debug is true then the events on this connection will be traced.
f8004d
  * This includes the incoming and outgoing message names.
f8004d
+ *
f8004d
+ * In case of failure, returns NULL and set @err with reason.
f8004d
  */
f8004d
 UdscsConnection *udscs_connect(const char *socketname,
f8004d
     udscs_read_callback read_callback,
f8004d
     VDAgentConnErrorCb error_cb,
f8004d
-    int debug);
f8004d
+    int debug,
f8004d
+    GError **err);
f8004d
 
f8004d
 /* Queue a message for delivery to the client connected through conn.
f8004d
  */
f8004d
diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
f8004d
index 0d3945e..05d1a8f 100644
f8004d
--- a/src/vdagent/vdagent.c
f8004d
+++ b/src/vdagent/vdagent.c
f8004d
@@ -376,22 +376,28 @@ static void vdagent_destroy(VDAgent *agent)
f8004d
 static gboolean vdagent_init_async_cb(gpointer user_data)
f8004d
 {
f8004d
     VDAgent *agent = user_data;
f8004d
+    GError *err = NULL;
f8004d
 
f8004d
     agent->conn = udscs_connect(vdagentd_socket,
f8004d
-                                daemon_read_complete, daemon_error_cb,
f8004d
-                                debug);
f8004d
+                                daemon_read_complete,
f8004d
+                                daemon_error_cb,
f8004d
+                                debug,
f8004d
+                                &err;;
f8004d
     if (agent->conn == NULL) {
f8004d
         if (agent->udscs_num_retry == MAX_RETRY_CONNECT_SYSTEM_AGENT) {
f8004d
             syslog(LOG_WARNING,
f8004d
                    "Failed to connect to spice-vdagentd at %s (tried %d times)",
f8004d
                    vdagentd_socket, agent->udscs_num_retry);
f8004d
+            g_error_free(err);
f8004d
             goto err_init;
f8004d
         }
f8004d
         if (agent->udscs_num_retry == 0) {
f8004d
             /* Log only when it fails and at the end */
f8004d
             syslog(LOG_DEBUG,
f8004d
-                   "Failed to connect with spice-vdagentd. Trying again in 1s");
f8004d
+                   "Failed to connect with spice-vdagentd due '%s'. Trying again in 1s",
f8004d
+                   err->message);
f8004d
         }
f8004d
+        g_error_free(err);
f8004d
         agent->udscs_num_retry++;
f8004d
         g_timeout_add_seconds(1, vdagent_init_async_cb, agent);
f8004d
         return G_SOURCE_REMOVE;
f8004d
-- 
f8004d
2.33.1
f8004d