提交 f4287c76 编写于 作者: D Daniel P. Berrange 提交者: Jiri Denemark

Add API for duplicating a socket/client file descriptor

* src/rpc/virnetsocket.c, src/rpc/virnetsocket.h: Add
  virNetSocketDupFD()
* src/rpc/virnetclient.c, src/rpc/virnetclient.h: Add
  virNetClientDupFD() and virNetClientGetFD()
上级 841a403f
...@@ -38,6 +38,7 @@ crypto/md5 ...@@ -38,6 +38,7 @@ crypto/md5
dirname-lgpl dirname-lgpl
environ environ
fclose fclose
fcntl
fcntl-h fcntl-h
ffs ffs
fnmatch fnmatch
......
...@@ -233,6 +233,26 @@ void virNetClientRef(virNetClientPtr client) ...@@ -233,6 +233,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, bool cloexec)
{
int fd;
virNetClientLock(client);
fd = virNetSocketDupFD(client->sock, cloexec);
virNetClientUnlock(client);
return fd;
}
void virNetClientFree(virNetClientPtr client) void virNetClientFree(virNetClientPtr client)
{ {
int i; int i;
......
...@@ -53,6 +53,9 @@ virNetClientPtr virNetClientNewExternal(const char **cmdargv); ...@@ -53,6 +53,9 @@ virNetClientPtr virNetClientNewExternal(const char **cmdargv);
void virNetClientRef(virNetClientPtr client); void virNetClientRef(virNetClientPtr client);
int virNetClientGetFD(virNetClientPtr client);
int virNetClientDupFD(virNetClientPtr client, bool cloexec);
int virNetClientAddProgram(virNetClientPtr client, int virNetClientAddProgram(virNetClientPtr client,
virNetClientProgramPtr prog); virNetClientProgramPtr prog);
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <unistd.h> #include <unistd.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <signal.h> #include <signal.h>
#include <fcntl.h>
#ifdef HAVE_NETINET_TCP_H #ifdef HAVE_NETINET_TCP_H
# include <netinet/tcp.h> # include <netinet/tcp.h>
...@@ -710,6 +711,23 @@ int virNetSocketGetFD(virNetSocketPtr sock) ...@@ -710,6 +711,23 @@ int virNetSocketGetFD(virNetSocketPtr sock)
} }
int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec)
{
int fd;
if (cloexec)
fd = fcntl(sock->fd, F_DUPFD_CLOEXEC);
else
fd = dup(sock->fd);
if (fd < 0) {
virReportSystemError(errno, "%s",
_("Unable to copy socket file handle"));
return -1;
}
return fd;
}
bool virNetSocketIsLocal(virNetSocketPtr sock) bool virNetSocketIsLocal(virNetSocketPtr sock)
{ {
bool isLocal = false; bool isLocal = false;
......
...@@ -77,6 +77,8 @@ int virNetSocketNewConnectExternal(const char **cmdargv, ...@@ -77,6 +77,8 @@ int virNetSocketNewConnectExternal(const char **cmdargv,
virNetSocketPtr *addr); virNetSocketPtr *addr);
int virNetSocketGetFD(virNetSocketPtr sock); int virNetSocketGetFD(virNetSocketPtr sock);
int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec);
bool virNetSocketIsLocal(virNetSocketPtr sock); bool virNetSocketIsLocal(virNetSocketPtr sock);
int virNetSocketGetPort(virNetSocketPtr sock); int virNetSocketGetPort(virNetSocketPtr sock);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册