From: Alon Levy <alevy@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH 1/5] oslib-posix: add qemu_pipe_non_block
Date: Tue, 4 Jun 2013 17:41:41 -0400 (EDT) [thread overview]
Message-ID: <378221460.14313718.1370382101151.JavaMail.root@redhat.com> (raw)
In-Reply-To: <51AE5808.6000000@redhat.com>
> On 06/04/2013 02:23 PM, Alon Levy wrote:
> > Used by the followin patch.
>
> s/followin/following/
Thanks.
>
> >
> > +int qemu_pipe_non_block(int pipefd[2])
> > +{
> > + int ret;
> > +
> > + ret = qemu_pipe(pipefd);
>
> qemu_pipe() already uses pipe2() when available; it seems like it would
> be nicer to use pipe2's O_NONBLOCK option directly in one syscall (where
> supported) instead of having to make additional syscalls after the fact.
> Would it just be smarter to change the signature of qemu_pipe() to add
> a bool block parameter, and then change the 5 existing callers to pass
> false with your later patch in the series passing true, and do it
> without creating a new wrapper?
Answered below.
>
> > + if (ret) {
> > + return ret;
> > + }
> > + if (fcntl(card->pipe[0], F_SETFL, O_NONBLOCK) == -1) {
> > + return -errno;
> > + }
> > + if (fcntl(card->pipe[1], F_SETFL, O_NONBLOCK) == -1) {
> > + return -errno;
>
> Leaks fds. If you're going to report error, then you must close the fds
> already created.
As Peter pointed out, I should not go here, so I'll drop these checks, instead doing naked fcntl calls, so no fd leak possible (no returns).
>
> > + }
> > + if (fcntl(card->pipe[0], F_SETOWN, getpid()) == -1) {
> > + return -errno;
>
> Same comment about fd leaks.
>
> This part seems like a useful change, IF you plan on using SIGIO and
> SIGURG signals; and it is something which pipe2() cannot optimize, so I
> can see why you are adding a new function instead of changing
> qemu_pipe() and adjust all its callers to pass an additional parameter.
> But are you really planning on using SIGIO/SIGURG?
I don't plan on using those signals, so I'll add a parameter instead.
>
> Furthermore, this is undefined behavior. According to POSIX, use of
> F_SETOWN is only portable on sockets, not pipes. It may work on Linux,
> but you'll need to be aware of what it does on other platforms.
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
> --
> Eric Blake eblake redhat com +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>
WARNING: multiple messages have this Message-ID (diff)
From: Alon Levy <alevy@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/5] oslib-posix: add qemu_pipe_non_block
Date: Tue, 4 Jun 2013 17:41:41 -0400 (EDT) [thread overview]
Message-ID: <378221460.14313718.1370382101151.JavaMail.root@redhat.com> (raw)
In-Reply-To: <51AE5808.6000000@redhat.com>
> On 06/04/2013 02:23 PM, Alon Levy wrote:
> > Used by the followin patch.
>
> s/followin/following/
Thanks.
>
> >
> > +int qemu_pipe_non_block(int pipefd[2])
> > +{
> > + int ret;
> > +
> > + ret = qemu_pipe(pipefd);
>
> qemu_pipe() already uses pipe2() when available; it seems like it would
> be nicer to use pipe2's O_NONBLOCK option directly in one syscall (where
> supported) instead of having to make additional syscalls after the fact.
> Would it just be smarter to change the signature of qemu_pipe() to add
> a bool block parameter, and then change the 5 existing callers to pass
> false with your later patch in the series passing true, and do it
> without creating a new wrapper?
Answered below.
>
> > + if (ret) {
> > + return ret;
> > + }
> > + if (fcntl(card->pipe[0], F_SETFL, O_NONBLOCK) == -1) {
> > + return -errno;
> > + }
> > + if (fcntl(card->pipe[1], F_SETFL, O_NONBLOCK) == -1) {
> > + return -errno;
>
> Leaks fds. If you're going to report error, then you must close the fds
> already created.
As Peter pointed out, I should not go here, so I'll drop these checks, instead doing naked fcntl calls, so no fd leak possible (no returns).
>
> > + }
> > + if (fcntl(card->pipe[0], F_SETOWN, getpid()) == -1) {
> > + return -errno;
>
> Same comment about fd leaks.
>
> This part seems like a useful change, IF you plan on using SIGIO and
> SIGURG signals; and it is something which pipe2() cannot optimize, so I
> can see why you are adding a new function instead of changing
> qemu_pipe() and adjust all its callers to pass an additional parameter.
> But are you really planning on using SIGIO/SIGURG?
I don't plan on using those signals, so I'll add a parameter instead.
>
> Furthermore, this is undefined behavior. According to POSIX, use of
> F_SETOWN is only portable on sockets, not pipes. It may work on Linux,
> but you'll need to be aware of what it does on other platforms.
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
> --
> Eric Blake eblake redhat com +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>
next prev parent reply other threads:[~2013-06-04 21:41 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-04 20:23 [Qemu-trivial] [PATCH 1/5] oslib-posix: add qemu_pipe_non_block Alon Levy
2013-06-04 20:23 ` [Qemu-devel] " Alon Levy
2013-06-04 20:23 ` [Qemu-trivial] [PATCH 2/5] use qemu_pipe_non_block Alon Levy
2013-06-04 20:23 ` [Qemu-devel] " Alon Levy
2013-06-04 20:47 ` [Qemu-trivial] " Paolo Bonzini
2013-06-04 20:47 ` [Qemu-devel] " Paolo Bonzini
2013-06-04 20:59 ` [Qemu-trivial] " Alon Levy
2013-06-04 20:59 ` Alon Levy
2013-06-04 21:08 ` [Qemu-trivial] " Peter Maydell
2013-06-04 21:08 ` Peter Maydell
2013-06-04 20:50 ` [Qemu-trivial] " Peter Maydell
2013-06-04 20:50 ` Peter Maydell
2013-06-04 20:56 ` [Qemu-trivial] " Alon Levy
2013-06-04 20:56 ` Alon Levy
2013-06-04 20:23 ` [Qemu-trivial] [PATCH 3/5] libcacard/vscclient: fix leakage of socket on error paths Alon Levy
2013-06-04 20:23 ` [Qemu-devel] " Alon Levy
2013-06-04 20:55 ` [Qemu-trivial] " Peter Maydell
2013-06-04 20:55 ` Peter Maydell
2013-06-12 12:09 ` [Qemu-trivial] " Michael Tokarev
2013-06-12 12:09 ` [Qemu-devel] " Michael Tokarev
2013-06-04 20:23 ` [Qemu-trivial] [PATCH 4/5] libcacard/vreader.c: fix possible NULL dereference Alon Levy
2013-06-04 20:23 ` [Qemu-devel] " Alon Levy
2013-06-04 21:06 ` [Qemu-trivial] " Peter Maydell
2013-06-04 21:06 ` Peter Maydell
2013-06-04 20:23 ` [Qemu-trivial] [PATCH 5/5] libcacard/vscclient.c: fix use of uninitialized variable Alon Levy
2013-06-04 20:23 ` [Qemu-devel] " Alon Levy
2013-06-04 21:12 ` [Qemu-trivial] " Peter Maydell
2013-06-04 21:12 ` Peter Maydell
2013-06-04 20:48 ` [Qemu-trivial] [Qemu-devel] [PATCH 1/5] oslib-posix: add qemu_pipe_non_block Peter Maydell
2013-06-04 20:48 ` Peter Maydell
2013-06-04 21:11 ` [Qemu-trivial] " Eric Blake
2013-06-04 21:11 ` Eric Blake
2013-06-04 21:41 ` Alon Levy [this message]
2013-06-04 21:41 ` Alon Levy
2013-06-05 19:43 ` [Qemu-trivial] " Michael Tokarev
2013-06-05 19:43 ` [Qemu-devel] " Michael Tokarev
2013-06-12 9:38 ` Michael Tokarev
2013-06-12 9:38 ` [Qemu-devel] " Michael Tokarev
2013-06-12 11:21 ` [Qemu-trivial] [Qemu-devel] " Alon Levy
2013-06-12 11:21 ` [Qemu-devel] [Qemu-trivial] " Alon Levy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=378221460.14313718.1370382101151.JavaMail.root@redhat.com \
--to=alevy@redhat.com \
--cc=eblake@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.