mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00: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;
|
||||
}
|
||||
|
||||
do {
|
||||
ret = virSocketSendFD(pair[1], fd);
|
||||
} while (ret < 0 && errno == EINTR);
|
||||
ret = virSocketSendFD(pair[1], fd);
|
||||
|
||||
if (ret < 0) {
|
||||
ret = -errno;
|
||||
|
@ -382,38 +382,16 @@ vir_socket(int domain, int type, int protocol)
|
||||
/* virSocketSendFD sends the file descriptor fd along the socket
|
||||
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
|
||||
virSocketSendFD(int sock, int fd)
|
||||
{
|
||||
char byte = 0;
|
||||
struct iovec iov;
|
||||
struct msghdr msg = { 0 };
|
||||
struct cmsghdr *cmsg;
|
||||
char buf[CMSG_SPACE(sizeof(fd))];
|
||||
int fds[] = { fd };
|
||||
|
||||
/* send at least one char */
|
||||
iov.iov_base = &byte;
|
||||
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;
|
||||
return virSocketSendMsgWithFDs(sock, &byte, sizeof(byte),
|
||||
fds, G_N_ELEMENTS(fds));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user