[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 03/14] Add API for duplicating a socket/client file descriptor



From: "Daniel P. Berrange" <berrange redhat com>

* src/rpc/virnetsocket.c, src/rpc/virnetsocket.h: Add
  virNetSocketDupFD()
* src/rpc/virnetclient.c, src/rpc/virnetclient.h: Add
  virNetClientDupFD() and virNetClientGetFD()
---
 src/rpc/virnetclient.c |   20 ++++++++++++++++++++
 src/rpc/virnetclient.h |    3 +++
 src/rpc/virnetsocket.c |   12 ++++++++++++
 src/rpc/virnetsocket.h |    2 ++
 4 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 615de6c..ecc5c37 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -217,6 +217,26 @@ void virNetClientRef(virNetClientPtr client)
 }
 
 
+int virNetClientGetFD(virNetClientPtr client)
+{
+    int fd;
+    virNetClientLock(client);
+    fd = virNetSocketGetFD(client->sock);
+    virNetClientUnlock(client);
+    return fd;
+}
+
+
+int virNetClientDupFD(virNetClientPtr client)
+{
+    int fd;
+    virNetClientLock(client);
+    fd = virNetSocketDupFD(client->sock);
+    virNetClientUnlock(client);
+    return fd;
+}
+
+
 void virNetClientFree(virNetClientPtr client)
 {
     int i;
diff --git a/src/rpc/virnetclient.h b/src/rpc/virnetclient.h
index de0782c..381d647 100644
--- a/src/rpc/virnetclient.h
+++ b/src/rpc/virnetclient.h
@@ -51,6 +51,9 @@ virNetClientPtr virNetClientNewExternal(const char **cmdargv);
 
 void virNetClientRef(virNetClientPtr client);
 
+int virNetClientGetFD(virNetClientPtr client);
+int virNetClientDupFD(virNetClientPtr client);
+
 int virNetClientAddProgram(virNetClientPtr client,
                            virNetClientProgramPtr prog);
 
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index 4b0c2ee..aff68bc 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -675,6 +675,18 @@ int virNetSocketGetFD(virNetSocketPtr sock)
 }
 
 
+int virNetSocketDupFD(virNetSocketPtr sock)
+{
+    int fd;
+    if ((fd = dup(sock->fd)) < 0) {
+        virReportSystemError(errno, "%s",
+                             _("Unable to copy socket file handle"));
+        return -1;
+    }
+    return fd;
+}
+
+
 bool virNetSocketIsLocal(virNetSocketPtr sock)
 {
     if (sock->localAddr.data.sa.sa_family == AF_UNIX)
diff --git a/src/rpc/virnetsocket.h b/src/rpc/virnetsocket.h
index 356d6c6..8053213 100644
--- a/src/rpc/virnetsocket.h
+++ b/src/rpc/virnetsocket.h
@@ -75,6 +75,8 @@ int virNetSocketNewConnectExternal(const char **cmdargv,
                                    virNetSocketPtr *addr);
 
 int virNetSocketGetFD(virNetSocketPtr sock);
+int virNetSocketDupFD(virNetSocketPtr sock);
+
 bool virNetSocketIsLocal(virNetSocketPtr sock);
 
 int virNetSocketGetPort(virNetSocketPtr sock);
-- 
1.7.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]