[Spice-devel] [PATCH vdagent 07/11] vdagent: small refactor on udscs setup function

Jakub Janků janku.jakub.jj at gmail.com
Tue Sep 26 20:59:43 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>
---
 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 21f88f8..0b6df3f 100644
--- a/src/vdagent/vdagent.c
+++ b/src/vdagent/vdagent.c
@@ -223,18 +223,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,
-                               NULL, vdagentd_messages, VDAGENTD_NO_MESSAGES,
-                               debug);
-        if (client || !reconnect || quit) {
+        conn = udscs_connect(vdagentd_socket, daemon_read_complete, NULL,
+                             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)
@@ -355,7 +357,8 @@ reconnect:
         execvp(argv[0], argv);
     }
 
-    if (client_setup(do_daemonize)) {
+    client = client_setup_sync();
+    if (client == NULL) {
         return 1;
     }
 
-- 
2.13.5



More information about the Spice-devel mailing list