All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>, Jeff Cody <jcody@redhat.com>,
	qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/3] qemu-img: fix img_commit() error return value
Date: Wed, 27 Aug 2014 08:31:59 +0200	[thread overview]
Message-ID: <87vbpefnog.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <53FCEB6A.9000401@redhat.com> (John Snow's message of "Tue, 26 Aug 2014 16:17:46 -0400")

John Snow <jsnow@redhat.com> writes:

> On 08/26/2014 03:31 PM, Eric Blake wrote:
>> On 08/26/2014 12:17 PM, Stefan Hajnoczi wrote:
>>> The img_commit() return value is a process exit code.  Use 1 for failure
>>> instead of -1.  The other failure paths in this function already use 1.
>>>
>>> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
>>> ---
>>>   qemu-img.c | 2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/qemu-img.c b/qemu-img.c
>>> index c843420..dc3adb5 100644
>>> --- a/qemu-img.c
>>> +++ b/qemu-img.c
>>> @@ -771,7 +771,7 @@ static int img_commit(int argc, char **argv)
>>>       ret = bdrv_parse_cache_flags(cache, &flags);
>>>       if (ret < 0) {
>>>           error_report("Invalid cache option: %s", cache);
>>> -        return -1;
>>> +        return 1;
>>
>> Nothing against this patch (you're consistent with the surrounding code,
>> and most of qemu for that matter), but it highlights why I'm a fan of
>> 'return EXIT_FAILURE' instead of 'return 1' in functions that return an
>> exit status, because that makes it a lot more obvious _why_ I'm
>> returning a non-negative number to represent failure.

For me, EXIT_FAILURE carries a smell.

In main(), the fact that we're returning an exit code is trivial.

Elsewhere, if all you want to return is "succeeded / failed" information
encoded as integer, stick to the usual 0/-1 convention, and leave
mapping that to exit codes to callers.

If you need to return one of several error codes, EXIT_FAILURE is of no
use.

> "Hey, good point."
>
> jsnow@local ~/s/qemu> git grep 'return 1;' | wc -l
> 842
>
> "oh."
>
> This patch is probably fine -- is there some larger scheme we want to
> cook up within the style guide for advocating things like return code
> and error reporting standards?
>
> It seems to me like the preferred style for errors and returns has
> changed several times and there's not a good concrete rule (written)
> at the moment. It might be worth touching the CODING_GUIDE and/or
> HACKING files with recommendations, if we can agree on some consistent
> set of rules, like getting rid of error_set(...) and not using
> positive, un-named integers to represent errors.

Yes, we could use some written guidance on returning errors.  I haven't
found the time to write.  When I can spare a bit of time for errors, I
tend to invest it in killing obsolete error reporting interfaces, so I
don't have to write guidance on them.

  reply	other threads:[~2014-08-27  6:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-26 18:17 [Qemu-devel] [PATCH 0/3] qemu-img: error path fixes Stefan Hajnoczi
2014-08-26 18:17 ` [Qemu-devel] [PATCH 1/3] qemu-img: fix img_commit() error return value Stefan Hajnoczi
2014-08-26 18:29   ` Max Reitz
2014-08-26 19:31   ` Eric Blake
2014-08-26 20:17     ` John Snow
2014-08-27  6:31       ` Markus Armbruster [this message]
2014-08-26 18:17 ` [Qemu-devel] [PATCH 2/3] qemu-img: fix img_compare() flags error path Stefan Hajnoczi
2014-08-26 18:30   ` Max Reitz
2014-08-26 18:17 ` [Qemu-devel] [PATCH 3/3] qemu-img: always goto out in img_snapshot() error paths Stefan Hajnoczi
2014-08-26 18:32   ` Max Reitz
2014-08-27  6:35   ` Markus Armbruster
2014-08-27 11:17     ` Stefan Hajnoczi
2014-08-26 21:02 ` [Qemu-devel] [PATCH 0/3] qemu-img: error path fixes John Snow
2014-08-27 11:17 ` Stefan Hajnoczi

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=87vbpefnog.fsf@blackfin.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=jcody@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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.