diff options
author | Corey Bryant <coreyb@linux.vnet.ibm.com> | 2012-08-14 16:43:42 -0400 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2012-08-15 10:48:57 +0200 |
commit | 06138651f3347a4ad7527d48b1ccbeae89f9e7f6 (patch) | |
tree | 1d3b6ef01875511ab5ca852641d40e1e225d4c93 /qemu-char.c | |
parent | 03834e22abafbc8dc4052d46a5ccd6dd135a54a3 (diff) | |
download | qemu-06138651f3347a4ad7527d48b1ccbeae89f9e7f6.zip qemu-06138651f3347a4ad7527d48b1ccbeae89f9e7f6.tar.gz qemu-06138651f3347a4ad7527d48b1ccbeae89f9e7f6.tar.bz2 |
qemu-char: Add MSG_CMSG_CLOEXEC flag to recvmsg
Set the close-on-exec flag for the file descriptor received
via SCM_RIGHTS.
Signed-off-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'qemu-char.c')
-rw-r--r-- | qemu-char.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/qemu-char.c b/qemu-char.c index 382c71e..10d1504 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2238,6 +2238,9 @@ static void unix_process_msgfd(CharDriverState *chr, struct msghdr *msg) if (fd < 0) continue; +#ifndef MSG_CMSG_CLOEXEC + qemu_set_cloexec(fd); +#endif if (s->msgfd != -1) close(s->msgfd); s->msgfd = fd; @@ -2253,6 +2256,7 @@ static ssize_t tcp_chr_recv(CharDriverState *chr, char *buf, size_t len) struct cmsghdr cmsg; char control[CMSG_SPACE(sizeof(int))]; } msg_control; + int flags = 0; ssize_t ret; iov[0].iov_base = buf; @@ -2263,9 +2267,13 @@ static ssize_t tcp_chr_recv(CharDriverState *chr, char *buf, size_t len) msg.msg_control = &msg_control; msg.msg_controllen = sizeof(msg_control); - ret = recvmsg(s->fd, &msg, 0); - if (ret > 0 && s->is_unix) +#ifdef MSG_CMSG_CLOEXEC + flags |= MSG_CMSG_CLOEXEC; +#endif + ret = recvmsg(s->fd, &msg, flags); + if (ret > 0 && s->is_unix) { unix_process_msgfd(chr, &msg); + } return ret; } |