From: Markus Armbruster <armbru@redhat.com>
To: Li Qiang <liq3ea@gmail.com>
Cc: peter.maydell@linaro.org, marcandre.lureau@redhat.com,
pbonzini@redhat.com, berrange@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2] util: check the return value of fcntl in qemu_set_{block, nonblock}
Date: Thu, 13 Dec 2018 13:38:20 +0100 [thread overview]
Message-ID: <87k1kda9fn.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <1544701071-2922-1-git-send-email-liq3ea@gmail.com> (Li Qiang's message of "Thu, 13 Dec 2018 03:37:51 -0800")
Li Qiang <liq3ea@gmail.com> writes:
> Also add diagnostics info in 'qemu_set_cloexec' so that we can know
> what happen when error occurs.
>
> Signed-off-by: Li Qiang <liq3ea@gmail.com>
> ---
> Change since v1: add diagnostics info
>
> util/oslib-posix.c | 37 ++++++++++++++++++++++++++++++++-----
> 1 file changed, 32 insertions(+), 5 deletions(-)
>
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index c1bee2a581..14cbef1e35 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -38,6 +38,7 @@
> #include <libgen.h>
> #include <sys/signal.h>
> #include "qemu/cutils.h"
> +#include "qemu/error-report.h"
>
> #ifdef CONFIG_LINUX
> #include <sys/syscall.h>
> @@ -233,14 +234,32 @@ void qemu_set_block(int fd)
> {
> int f;
> f = fcntl(fd, F_GETFL);
> - fcntl(fd, F_SETFL, f & ~O_NONBLOCK);
> + if (f < 0) {
> + error_report("Unable to get file status flag on fd %d: %s(errno=%d)",
> + fd, strerror(errno), errno);
> + abort();
> + }
> + if (fcntl(fd, F_SETFL, f & ~O_NONBLOCK) < 0) {
> + error_report("Unable to set blocking flag on fd %d: %s(errno=%d)",
> + fd, strerror(errno), errno);
> + abort();
> + }
> }
If this is a programming error, i.e. one that can happen only when the
function gets misused, then abort() is appropriate, but error_report()
is putting lipstick on the pig.
If it's not a programming error, but something outside QEMU misbehaves
(user error, network outage, ...), then error_report() is appropriate,
but abort() is not. exit(1) then.
[...]
next prev parent reply other threads:[~2018-12-13 12:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-13 11:37 [Qemu-devel] [PATCH v2] util: check the return value of fcntl in qemu_set_{block, nonblock} Li Qiang
2018-12-13 11:45 ` Peter Maydell
2018-12-13 11:48 ` Daniel P. Berrangé
2018-12-13 11:49 ` Li Qiang
2018-12-13 12:38 ` Markus Armbruster [this message]
2018-12-13 16:01 ` no-reply
2018-12-14 1:46 ` Li Qiang
2018-12-14 9:15 ` Li Qiang
2018-12-14 9:49 ` Peter Maydell
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=87k1kda9fn.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=liq3ea@gmail.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@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.