[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v5 1/6] qemu-char: Add MSG_CMSG_CLOEXEC flag to
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v5 1/6] qemu-char: Add MSG_CMSG_CLOEXEC flag to recvmsg |
Date: |
Mon, 23 Jul 2012 16:50:10 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120717 Thunderbird/14.0 |
On 07/23/2012 07:08 AM, Corey Bryant wrote:
> Set the close-on-exec flag for the file descriptor received
> via SCM_RIGHTS.
>
> +++ b/qemu-char.c
> @@ -2263,9 +2263,17 @@ static ssize_t tcp_chr_recv(CharDriverState *chr, char
> *buf, size_t len)
> msg.msg_control = &msg_control;
> msg.msg_controllen = sizeof(msg_control);
>
> +#ifdef MSG_CMSG_CLOEXEC
> + ret = recvmsg(s->fd, &msg, MSG_CMSG_CLOEXEC);
> +#else
> ret = recvmsg(s->fd, &msg, 0);
> - if (ret > 0 && s->is_unix)
> + if (ret > 0) {
> + qemu_set_cloexec(s->fd);
Wrong fd. You aren't changing cloexec on the socket (s->fd), but on the
fd that was received via msg (which you don't know at this point in time).
> + }
> +#endif
> + if (ret > 0 && s->is_unix) {
> unix_process_msgfd(chr, &msg);
Only here do you know what fd you received.
I would write it more like:
int flags = 0;
#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);
#ifndef MSG_CMSG_CLOEXEC
qemu_set_cloexec(/* fd determined from msg */)
#endif
}
which almost implies that unix_process_msgfd() should be the function
that sets cloexec, but without wasting the time doing so if recvmsg
already did the job.
--
Eric Blake address@hidden +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH v5 6/6] block: Enable qemu_open/close to work with fd sets, (continued)
Re: [Qemu-devel] [PATCH v5 6/6] block: Enable qemu_open/close to work with fd sets, Eric Blake, 2012/07/25
[Qemu-devel] [PATCH v5 5/6] block: Convert close calls to qemu_close, Corey Bryant, 2012/07/23
[Qemu-devel] [PATCH v5 1/6] qemu-char: Add MSG_CMSG_CLOEXEC flag to recvmsg, Corey Bryant, 2012/07/23
- Re: [Qemu-devel] [PATCH v5 1/6] qemu-char: Add MSG_CMSG_CLOEXEC flag to recvmsg,
Eric Blake <=
[Qemu-devel] [PATCH v5 4/6] block: Convert open calls to qemu_open, Corey Bryant, 2012/07/23
[Qemu-devel] [PATCH v5 2/6] qapi: Introduce add-fd, remove-fd, query-fdsets, Corey Bryant, 2012/07/23
Re: [Qemu-devel] [PATCH v5 0/6] file descriptor passing using fd sets, Kevin Wolf, 2012/07/24