From: Eric Blake <eblake@redhat.com>
To: Ian Jackson <ian.jackson@citrix.com>
Cc: qemu-devel@nongnu.org, "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Daniel P.Berrangé" <berrange@redhat.com>,
"Alistair Francis" <alistair.francis@xilinx.com>,
"Markus Armbruster" <armbru@redhat.com>
Subject: Re: [Qemu-devel] [RFC PATCH 1/7] error reporting: Introduce errnoval parameter to vreport
Date: Thu, 26 Apr 2018 12:45:02 -0500 [thread overview]
Message-ID: <d78d25c0-3259-6f71-34f7-321140b87c69@redhat.com> (raw)
In-Reply-To: <23266.3384.611703.928502@mariner.uk.xensource.com>
[-- Attachment #1: Type: text/plain, Size: 2612 bytes --]
On 04/26/2018 12:32 PM, Ian Jackson wrote:
>>> * Print a message to current monitor if we have one, else to stderr.
>>> * @report_type is the type of message: error, warning or informational.
>>> + * If @errnoval is nonnegative it is fed to strerror and printed too.
>>
>> That implies 0 is fed to strerror(), which is not the case.
>
> But, 0 might be fed to strerror. This is not normally deliberate, but
> it does occor. It is not unusual for people to write code which can
> feed 0 to strerror. strerror then conventionally returns "Error 0".
No, POSIX requires:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html
"if the value of errnum is zero, the message string shall either be an
empty string or indicate that no error occurred;"
and at least in glibc, strerror(0) returns "Success", which looks dumb
in an error message.
>
> This is why I chose -1 as the sentinel value meaning "there is no
> errno being passed".
>
>> "If @errnoval is not zero, its absolute value is fed to strerror" to let
>> people pass in both EIO and -EIO for the same output (something that
>> strerror() can't do, but our wrapper can) - but I don't know if that
>> convenience is a good thing.
>
> I think it is more important not to turn inintended situations where 0
> would previously have been passed to strerror, into situations where
> the errno value string simply vanishes.
Passing 0 as an errno value to indicate an error is almost always wrong.
But if you don't have an errno value to report, having the error string
disappear is preferable to outputting garbage or even assert()ing that
the error value was nonzero.
>>
>> Passing -1 to suppress the output feels awkward, especially if 0 can be
>> used for the same purpose and would then let us use -errno and errno
>> interchangeable by passing the absolute value to sterror.
>
> I think no good can come of taking the absolute value. The confusion
> resulting from -errnoval is bad enough already IMO.
You are correct that in the past, we've had code passing or returning
the wrong sign without realizing it. So the question is whether, at
least for reporting purposes, it looks better to report "Operation not
permitted" instead of "Unknown error -1", or whether munging the error
message as a convenience for better output makes it harder for the
programmer to realize that they are returning the wrong sign up the
stack to the caller.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]
next prev parent reply other threads:[~2018-04-26 17:45 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-26 16:53 [Qemu-devel] [RFC PATCH 0/7] Introduce error_[v]report_errno[val] Ian Jackson
2018-04-26 16:53 ` [Qemu-devel] [RFC PATCH 1/7] error reporting: Introduce errnoval parameter to vreport Ian Jackson
2018-04-26 17:24 ` Eric Blake
2018-04-26 17:32 ` Ian Jackson
2018-04-26 17:45 ` Eric Blake [this message]
2018-04-26 18:23 ` Ian Jackson
2018-04-26 18:12 ` Eric Blake
2018-04-26 16:53 ` [Qemu-devel] [RFC PATCH 2/7] error reporting: Provide error_report_errno (and error_vreport_errno) Ian Jackson
2018-04-26 17:27 ` Eric Blake
2018-04-26 16:53 ` [Qemu-devel] [RFC PATCH 3/7] error reporting: Use error_report_errno in obvious places Ian Jackson
2018-04-26 17:37 ` Eric Blake
2018-04-26 17:43 ` Ian Jackson
2018-04-26 18:07 ` Eric Blake
2018-04-26 16:53 ` [Qemu-devel] [RFC PATCH 4/7] error reporting: Fix some error messages to use ":" rather than ", " Ian Jackson
2018-04-26 16:53 ` [Qemu-devel] [RFC PATCH 5/7] error reporting: Provide error_report_errnoval (and error_vreport_errnoval) Ian Jackson
2018-04-26 17:31 ` Eric Blake
2018-04-26 17:42 ` Ian Jackson
2018-04-26 16:53 ` [Qemu-devel] [RFC PATCH 6/7] error reporting: Use error_report_errnoval in obvious places Ian Jackson
2018-04-26 16:53 ` [Qemu-devel] [RFC PATCH 7/7] error reporting: HACKING: Say to use error_report_errno Ian Jackson
2018-04-26 17:51 ` Eric Blake
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=d78d25c0-3259-6f71-34f7-321140b87c69@redhat.com \
--to=eblake@redhat.com \
--cc=alistair.francis@xilinx.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=f4bug@amsat.org \
--cc=ian.jackson@citrix.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).