[Spice-devel] [PATCH v4 5/8] vdagent: small refactor on udscs setup function

Frediano Ziglio fziglio at redhat.com
Mon Oct 16 14:38:12 UTC 2017


From: Victor Toso <me at victortoso.com>

This is mostly a preparatory patch to reduce the usage of globals and
the GMainLoop integration. The changes target one function by:

* Changing its name from client_setup() to client_setup_sync(): As it
  important to clarify that the function block;

* Removing the 'reconnect' argument as the input is the global
  'do_daemonize'. We can use the global here as it is related to
  command line options;

* Changing the return value from 'int' to 'udscs_connection *' as the
  followup patch will remove the global variable 'client'.

Signed-off-by: Victor Toso <victortoso at redhat.com>
Acked-by: Frediano Ziglio <fziglio at redhat.com>
---
 src/vdagent/vdagent.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
index b7dc4a5..1f44728 100644
--- a/src/vdagent/vdagent.c
+++ b/src/vdagent/vdagent.c
@@ -230,18 +230,20 @@ static void daemon_read_complete(struct udscs_connection **connp,
     }
 }
 
-static int client_setup(int reconnect)
+static struct udscs_connection *client_setup_sync(void)
 {
+    struct udscs_connection *conn = NULL;
+
     while (!quit) {
-        client = udscs_connect(vdagentd_socket, daemon_read_complete, NULL,
-                               vdagentd_messages, VDAGENTD_NO_MESSAGES,
-                               debug);
-        if (client || !reconnect || quit) {
+        conn = udscs_connect(vdagentd_socket, daemon_read_complete, NULL,
+                             vdagentd_messages, VDAGENTD_NO_MESSAGES,
+                             debug);
+        if (conn || !do_daemonize || quit) {
             break;
         }
         sleep(1);
     }
-    return client == NULL;
+    return conn;
 }
 
 static void quit_handler(int sig)
@@ -360,7 +362,8 @@ reconnect:
         execvp(argv[0], argv);
     }
 
-    if (client_setup(do_daemonize)) {
+    client = client_setup_sync();
+    if (client == NULL) {
         return 1;
     }
 
-- 
2.13.6



More information about the Spice-devel mailing list