]> xenbits.xensource.com Git - libvirt.git/commitdiff
virNetSocket: allow to not close FD
authorPino Toscano <ptoscano@redhat.com>
Wed, 9 Nov 2016 14:28:32 +0000 (15:28 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 15 Nov 2016 14:50:51 +0000 (15:50 +0100)
Add an internal variable to mark the FD as "not owned" by the
virNetSocket, in case the internal implementation takes the actual
ownership of the descriptor; this avoids a warning when closing the
socket, as the FD would be invalid.

src/rpc/virnetsocket.c

index 405f5ba30e41b5d617b77715bdca184944ed5ac9..05f20a595389c02f5f0c2445bd31b792383f86ca 100644 (file)
@@ -77,6 +77,7 @@ struct _virNetSocket {
     pid_t pid;
     int errfd;
     bool client;
+    bool ownsFd;
 
     /* Event callback fields */
     virNetSocketIOFunc func;
@@ -248,6 +249,7 @@ static virNetSocketPtr virNetSocketNew(virSocketAddrPtr localAddr,
     sock->errfd = errfd;
     sock->pid = pid;
     sock->watch = -1;
+    sock->ownsFd = true;
 
     /* Disable nagle for TCP sockets */
     if (sock->localAddr.data.sa.sa_family == AF_INET ||
@@ -1202,7 +1204,8 @@ void virNetSocketDispose(void *obj)
     virObjectUnref(sock->sshSession);
 #endif
 
-    VIR_FORCE_CLOSE(sock->fd);
+    if (sock->ownsFd)
+        VIR_FORCE_CLOSE(sock->fd);
     VIR_FORCE_CLOSE(sock->errfd);
 
     virProcessAbort(sock->pid);