mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
fish: rc: Fail hard if recvmsg doesn't receive a file descriptor.
Also some code reformatting.
This commit is contained in:
32
fish/rc.c
32
fish/rc.c
@@ -92,10 +92,11 @@ static void
|
||||
receive_stdout (int s)
|
||||
{
|
||||
static struct cmsghdr *cmptr = NULL, *h;
|
||||
struct msghdr msg;
|
||||
struct iovec iov[1];
|
||||
|
||||
/* Our 1 byte buffer */
|
||||
struct msghdr msg;
|
||||
struct iovec iov[1];
|
||||
ssize_t n;
|
||||
void *data;
|
||||
int fd;
|
||||
char buf[1];
|
||||
|
||||
if (NULL == cmptr) {
|
||||
@@ -120,24 +121,21 @@ receive_stdout (int s)
|
||||
msg.msg_controllen = controllen;
|
||||
|
||||
/* Read a message from the socket */
|
||||
ssize_t n = recvmsg (s, &msg, 0);
|
||||
n = recvmsg (s, &msg, 0);
|
||||
if (n < 0)
|
||||
error (EXIT_FAILURE, errno, "recvmsg stdout fd");
|
||||
|
||||
h = CMSG_FIRSTHDR(&msg);
|
||||
if (NULL == h) {
|
||||
fprintf (stderr, "didn't receive a stdout file descriptor\n");
|
||||
}
|
||||
h = CMSG_FIRSTHDR (&msg);
|
||||
if (NULL == h)
|
||||
error (EXIT_FAILURE, errno, "didn't receive a stdout file descriptor");
|
||||
|
||||
else {
|
||||
/* Extract the transferred file descriptor from the control data */
|
||||
void *data = CMSG_DATA (h);
|
||||
int fd = *(int *)data;
|
||||
/* Extract the transferred file descriptor from the control data */
|
||||
data = CMSG_DATA (h);
|
||||
fd = *(int *)data;
|
||||
|
||||
/* Duplicate the received file descriptor to stdout */
|
||||
dup2 (fd, STDOUT_FILENO);
|
||||
close (fd);
|
||||
}
|
||||
/* Duplicate the received file descriptor to stdout */
|
||||
dup2 (fd, STDOUT_FILENO);
|
||||
close (fd);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user