From: "Daniel P. Berrange" <berrange@xxxxxxxxxx> To allow creation of a virNetSocketPtr instance from a pre-opened socketpair FD, add a virNetSocketNewConnectSockFD method. Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx> --- 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 50e2f48..9e2beda 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1010,6 +1010,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); -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list