]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
rpc: socket: Minor cleanups
authorCole Robinson <crobinso@redhat.com>
Tue, 12 Jan 2016 01:01:24 +0000 (20:01 -0500)
committerCole Robinson <crobinso@redhat.com>
Thu, 21 Jan 2016 00:10:03 +0000 (19:10 -0500)
- Add some debugging
- Make the loop dependent only on retries
- Make it explicit that connect(2) success exits the loop
- Invert the error checking logic

(cherry picked from commit f102c7146ed7f6e04af0ad3bce302476239f2502)

src/rpc/virnetsocket.c

index 6153e0e7cbccae1d43ef7bedaaba71716ce0ad98..dcff69e5fd40734586bc7d8e1e884d87c242c18b 100644 (file)
@@ -548,6 +548,9 @@ int virNetSocketNewConnectUNIX(const char *path,
     char *rundir = NULL;
     int ret = -1;
 
+    VIR_DEBUG("path=%s spawnDaemon=%d binary=%s", path, spawnDaemon,
+        NULLSTR(binary));
+
     memset(&localAddr, 0, sizeof(localAddr));
     memset(&remoteAddr, 0, sizeof(remoteAddr));
 
@@ -608,10 +611,15 @@ int virNetSocketNewConnectUNIX(const char *path,
     if (remoteAddr.data.un.sun_path[0] == '@')
         remoteAddr.data.un.sun_path[0] = '\0';
 
-    while (retries &&
-           connect(fd, &remoteAddr.data.sa, remoteAddr.len) < 0) {
-        if (!(spawnDaemon && (errno == ENOENT ||
-                              errno == ECONNREFUSED))) {
+    while (retries) {
+        if (connect(fd, &remoteAddr.data.sa, remoteAddr.len) == 0) {
+            VIR_DEBUG("connect() succeeded");
+            break;
+        }
+        VIR_DEBUG("connect() failed: retries=%d errno=%d", retries, errno);
+
+        if (!spawnDaemon ||
+            (errno != ENOENT && errno != ECONNREFUSED)) {
             virReportSystemError(errno, _("Failed to connect socket to '%s'"),
                                  path);
             goto cleanup;