]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
rpc: socket: Add possibility to suppress errors on read hangup
authorPeter Krempa <pkrempa@redhat.com>
Fri, 17 Mar 2017 15:01:45 +0000 (16:01 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 17 Mar 2017 16:19:00 +0000 (17:19 +0100)
In some cases a read error due to connection hangup is expected. This
patch adds a flag that removes the logging of a virError in such case.

src/rpc/virnetsocket.c
src/rpc/virnetsocket.h

index 325a7c7cf654a7b4e5a7c1552305f4456ff4f585..d228c8a8c879164e5c474eaa6d75bea39ad585e4 100644 (file)
@@ -82,6 +82,7 @@ struct _virNetSocket {
     int errfd;
     bool client;
     bool ownsFd;
+    bool quietEOF;
 
     /* Event callback fields */
     virNetSocketIOFunc func;
@@ -1792,13 +1793,22 @@ static ssize_t virNetSocketReadWire(virNetSocketPtr sock, char *buf, size_t len)
                                  _("Cannot recv data"));
         ret = -1;
     } else if (ret == 0) {
-        if (errout)
-            virReportSystemError(EIO,
-                                 _("End of file while reading data: %s"), errout);
-        else
-            virReportSystemError(EIO, "%s",
-                                 _("End of file while reading data"));
-        ret = -1;
+        if (sock->quietEOF) {
+            VIR_DEBUG("socket='%p' EOF while reading: errout='%s'",
+                      socket, NULLSTR(errout));
+
+            ret = -2;
+        } else {
+            if (errout)
+                virReportSystemError(EIO,
+                                     _("End of file while reading data: %s"),
+                                     errout);
+            else
+                virReportSystemError(EIO, "%s",
+                                     _("End of file while reading data"));
+
+            ret = -1;
+        }
     }
 
     VIR_FREE(errout);
@@ -2233,3 +2243,17 @@ void virNetSocketClose(virNetSocketPtr sock)
 
     virObjectUnlock(sock);
 }
+
+
+/**
+ * virNetSocketSetQuietEOF:
+ * @sock: socket object pointer
+ *
+ * Disables reporting I/O errors as a virError when @socket is closed while
+ * reading data.
+ */
+void
+virNetSocketSetQuietEOF(virNetSocketPtr sock)
+{
+    sock->quietEOF = true;
+}
index 56c75c03033970a8da6b35e620dd31fd81fdd30a..1e75ee62b2964e1867641a74fea3cfb5d0660027 100644 (file)
@@ -143,6 +143,8 @@ int virNetSocketGetSELinuxContext(virNetSocketPtr sock,
 int virNetSocketSetBlocking(virNetSocketPtr sock,
                             bool blocking);
 
+void virNetSocketSetQuietEOF(virNetSocketPtr sock);
+
 ssize_t virNetSocketRead(virNetSocketPtr sock, char *buf, size_t len);
 ssize_t virNetSocketWrite(virNetSocketPtr sock, const char *buf, size_t len);