mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virsocket: Simplify virSocketSendFD()
After previous cleanups, virSocketSendFD() is but a thin wrapper over virSocketSendMsgWithFDs(). Replace the body of the former with a call to the latter. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
495a826dbf
commit
91f4ebbac8
@ -2445,9 +2445,7 @@ virFileOpenForked(const char *path, int openflags, mode_t mode,
|
|||||||
goto childerror;
|
goto childerror;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
ret = virSocketSendFD(pair[1], fd);
|
||||||
ret = virSocketSendFD(pair[1], fd);
|
|
||||||
} while (ret < 0 && errno == EINTR);
|
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
|
@ -382,38 +382,16 @@ vir_socket(int domain, int type, int protocol)
|
|||||||
/* virSocketSendFD sends the file descriptor fd along the socket
|
/* virSocketSendFD sends the file descriptor fd along the socket
|
||||||
to a process calling virSocketRecvFD on the other end.
|
to a process calling virSocketRecvFD on the other end.
|
||||||
|
|
||||||
Return 0 on success, or -1 with errno set in case of error.
|
Return 1 on success, or -1 with errno set in case of error.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virSocketSendFD(int sock, int fd)
|
virSocketSendFD(int sock, int fd)
|
||||||
{
|
{
|
||||||
char byte = 0;
|
char byte = 0;
|
||||||
struct iovec iov;
|
int fds[] = { fd };
|
||||||
struct msghdr msg = { 0 };
|
|
||||||
struct cmsghdr *cmsg;
|
|
||||||
char buf[CMSG_SPACE(sizeof(fd))];
|
|
||||||
|
|
||||||
/* send at least one char */
|
return virSocketSendMsgWithFDs(sock, &byte, sizeof(byte),
|
||||||
iov.iov_base = &byte;
|
fds, G_N_ELEMENTS(fds));
|
||||||
iov.iov_len = 1;
|
|
||||||
msg.msg_iov = &iov;
|
|
||||||
msg.msg_iovlen = 1;
|
|
||||||
msg.msg_name = NULL;
|
|
||||||
msg.msg_namelen = 0;
|
|
||||||
|
|
||||||
msg.msg_control = buf;
|
|
||||||
msg.msg_controllen = sizeof(buf);
|
|
||||||
cmsg = CMSG_FIRSTHDR(&msg);
|
|
||||||
cmsg->cmsg_level = SOL_SOCKET;
|
|
||||||
cmsg->cmsg_type = SCM_RIGHTS;
|
|
||||||
cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
|
|
||||||
/* Initialize the payload: */
|
|
||||||
memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd));
|
|
||||||
msg.msg_controllen = cmsg->cmsg_len;
|
|
||||||
|
|
||||||
if (sendmsg(sock, &msg, 0) != iov.iov_len)
|
|
||||||
return -1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user