Blob Blame History Raw
From 9e7cec4d755341cfb4c27c16aa59b22135612f0e Mon Sep 17 00:00:00 2001
From: "Daniel P. Berrange" <berrange@redhat.com>
Date: Mon, 23 Sep 2013 12:46:26 +0100
Subject: [PATCH] Add a virNetSocketNewConnectSockFD method

To allow creation of a virNetSocketPtr instance from a pre-opened
socketpair FD, add a virNetSocketNewConnectSockFD method.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 src/libvirt_private.syms |  1 +
 src/rpc/virnetsocket.c   | 18 ++++++++++++++++++
 src/rpc/virnetsocket.h   |  2 ++
 3 files changed, 21 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 35f0f1b..873d93d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1008,6 +1008,7 @@ virNetSocketLocalAddrString;
 virNetSocketNewConnectCommand;
 virNetSocketNewConnectExternal;
 virNetSocketNewConnectLibSSH2;
+virNetSocketNewConnectSockFD;
 virNetSocketNewConnectSSH;
 virNetSocketNewConnectTCP;
 virNetSocketNewConnectUNIX;
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index ae81512..b311aae 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -884,6 +884,24 @@ int virNetSocketNewConnectExternal(const char **cmdargv,
 }
 
 
+int virNetSocketNewConnectSockFD(int sockfd,
+                                 virNetSocketPtr *retsock)
+{
+    virSocketAddr localAddr;
+
+    localAddr.len = sizeof(localAddr.data);
+    if (getsockname(sockfd, &localAddr.data.sa, &localAddr.len) < 0) {
+        virReportSystemError(errno, "%s", _("Unable to get local socket name"));
+        return -1;
+    }
+
+    if (!(*retsock = virNetSocketNew(&localAddr, NULL, true, sockfd, -1, -1)))
+        return -1;
+
+    return 0;
+}
+
+
 virNetSocketPtr virNetSocketNewPostExecRestart(virJSONValuePtr object)
 {
     virSocketAddr localAddr;
diff --git a/src/rpc/virnetsocket.h b/src/rpc/virnetsocket.h
index ca9ae91..86bc2f6 100644
--- a/src/rpc/virnetsocket.h
+++ b/src/rpc/virnetsocket.h
@@ -97,6 +97,8 @@ int virNetSocketNewConnectLibSSH2(const char *host,
 int virNetSocketNewConnectExternal(const char **cmdargv,
                                    virNetSocketPtr *addr);
 
+int virNetSocketNewConnectSockFD(int sockfd,
+                                 virNetSocketPtr *retsock);
 
 virNetSocketPtr virNetSocketNewPostExecRestart(virJSONValuePtr object);