mirror of https://gitee.com/openkylin/libvirt.git
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()
This commit is contained in:
parent
841a403f94
commit
f4287c7676
|
@ -38,6 +38,7 @@ crypto/md5
|
|||
dirname-lgpl
|
||||
environ
|
||||
fclose
|
||||
fcntl
|
||||
fcntl-h
|
||||
ffs
|
||||
fnmatch
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
int i;
|
||||
|
|
|
@ -53,6 +53,9 @@ virNetClientPtr virNetClientNewExternal(const char **cmdargv);
|
|||
|
||||
void virNetClientRef(virNetClientPtr client);
|
||||
|
||||
int virNetClientGetFD(virNetClientPtr client);
|
||||
int virNetClientDupFD(virNetClientPtr client, bool cloexec);
|
||||
|
||||
int virNetClientAddProgram(virNetClientPtr client,
|
||||
virNetClientProgramPtr prog);
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef HAVE_NETINET_TCP_H
|
||||
# include <netinet/tcp.h>
|
||||
|
@ -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 isLocal = false;
|
||||
|
|
|
@ -77,6 +77,8 @@ int virNetSocketNewConnectExternal(const char **cmdargv,
|
|||
virNetSocketPtr *addr);
|
||||
|
||||
int virNetSocketGetFD(virNetSocketPtr sock);
|
||||
int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec);
|
||||
|
||||
bool virNetSocketIsLocal(virNetSocketPtr sock);
|
||||
|
||||
int virNetSocketGetPort(virNetSocketPtr sock);
|
||||
|
|
Loading…
Reference in New Issue