]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: let virSetSockReuseAddr report unified error message
authorMartin Kletzander <mkletzan@redhat.com>
Sun, 7 Sep 2014 15:05:03 +0000 (17:05 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Tue, 9 Sep 2014 13:14:24 +0000 (15:14 +0200)
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/rpc/virnetsocket.c
src/util/virportallocator.c
src/util/virutil.c
src/util/virutil.h

index 586a0d744aee31146d85d5ad7bae4b21be11c71e..2192dc8d1c72fe2bb5e1904dc12ba2b86ee0ba8e 100644 (file)
@@ -278,10 +278,8 @@ int virNetSocketNewListenTCP(const char *nodename,
             goto error;
         }
 
-        if (virSetSockReuseAddr(fd) < 0) {
-            virReportSystemError(errno, "%s", _("Unable to enable port reuse"));
+        if (virSetSockReuseAddr(fd, true) < 0)
             goto error;
-        }
 
 #ifdef IPV6_V6ONLY
         if (runp->ai_family == PF_INET6) {
@@ -493,9 +491,8 @@ int virNetSocketNewConnectTCP(const char *nodename,
             goto error;
         }
 
-        if (virSetSockReuseAddr(fd) < 0) {
+        if (virSetSockReuseAddr(fd, false) < 0)
             VIR_WARN("Unable to enable port reuse");
-        }
 
         if (connect(fd, runp->ai_addr, runp->ai_addrlen) >= 0)
             break;
index ff5691a2b7db0610312cb1d659384dd5387a22a6..f1dade3f241ca4630e55ba489753ef98af321d99 100644 (file)
@@ -142,11 +142,8 @@ static int virPortAllocatorBindToPort(bool *used,
         goto cleanup;
     }
 
-    if (virSetSockReuseAddr(fd) < 0) {
-        virReportSystemError(errno, "%s",
-                             _("Unable to set socket reuse addr flag"));
+    if (virSetSockReuseAddr(fd, true) < 0)
         goto cleanup;
-    }
 
     if (ipv6 && setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&v6only,
                            sizeof(v6only)) < 0) {
index 04113bbe554dac35e0a3c53d2bc13075b866555b..8d2f62a20cfc60768dfb1b0062f29fafeb61b7ec 100644 (file)
@@ -148,7 +148,7 @@ int virSetCloseExec(int fd)
 }
 
 #ifdef WIN32
-int virSetSockReuseAddr(int fd ATTRIBUTE_UNUSED)
+int virSetSockReuseAddr(int fd ATTRIBUTE_UNUSED, bool fatal ATTRIBUTE_UNUSED)
 {
     /*
      * SO_REUSEADDR on Windows is actually akin to SO_REUSEPORT
@@ -163,10 +163,17 @@ int virSetSockReuseAddr(int fd ATTRIBUTE_UNUSED)
     return 0;
 }
 #else
-int virSetSockReuseAddr(int fd)
+int virSetSockReuseAddr(int fd, bool fatal)
 {
     int opt = 1;
-    return setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+    int ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+
+    if (ret < 0 && fatal) {
+        virReportSystemError(errno, "%s",
+                             _("Unable to set socket reuse addr flag"));
+    }
+
+    return ret;
 }
 #endif
 
index 89b79235c332230a1d7be6b5dab3ce85493133a9..54f11488f8e1fe999dc4e3bc47cfc95459151cb8 100644 (file)
@@ -43,7 +43,7 @@ int virSetBlocking(int fd, bool blocking) ATTRIBUTE_RETURN_CHECK;
 int virSetNonBlock(int fd) ATTRIBUTE_RETURN_CHECK;
 int virSetInherit(int fd, bool inherit) ATTRIBUTE_RETURN_CHECK;
 int virSetCloseExec(int fd) ATTRIBUTE_RETURN_CHECK;
-int virSetSockReuseAddr(int fd) ATTRIBUTE_RETURN_CHECK;
+int virSetSockReuseAddr(int fd, bool fatal) ATTRIBUTE_RETURN_CHECK;
 
 int virPipeReadUntilEOF(int outfd, int errfd,
                         char **outbuf, char **errbuf);