diff mbox

[1/3] rpc: socket: Minor cleanups

Message ID 3d5ffbb7ad8575a00e25372d18d2398c16a8d98f.1452561712.git.crobinso@redhat.com
State Accepted
Commit f102c7146ed7f6e04af0ad3bce302476239f2502
Headers show

Commit Message

Cole Robinson Jan. 12, 2016, 1:22 a.m. UTC
- 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
---
 src/rpc/virnetsocket.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

-- 
2.5.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox

Patch

diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index 4f67c8f..80c21c1 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -620,6 +620,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));
 
@@ -680,10 +683,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, errno=%d", errno);
+
+        if (!spawnDaemon ||
+            (errno != ENOENT && errno != ECONNREFUSED)) {
             virReportSystemError(errno, _("Failed to connect socket to '%s'"),
                                  path);
             goto cleanup;