From: "Benoît Canet" <benoit.canet@irqsave.net>
To: Max Reitz <mreitz@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] util/error: Save errno from clobbering
Date: Thu, 7 Nov 2013 20:18:45 +0100 [thread overview]
Message-ID: <20131107191845.GG2921@irqsave.net> (raw)
In-Reply-To: <1383851429-9213-1-git-send-email-mreitz@redhat.com>
Le Thursday 07 Nov 2013 à 20:10:29 (+0100), Max Reitz a écrit :
> There may be calls to error_setg() and especially error_setg_errno()
> which blindly (and until now wrongly) assume these functions not to
> clobber errno (e.g., they pass errno to error_setg_errno() and return
> -errno afterwards). Instead of trying to find and fix all of these
> constructs, just make sure error_setg() and error_setg_errno() indeed do
> not clobber errno.
>
> Suggested-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> util/error.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/util/error.c b/util/error.c
> index ec0faa6..3ee362a 100644
> --- a/util/error.c
> +++ b/util/error.c
> @@ -27,6 +27,7 @@ void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...)
> {
> Error *err;
> va_list ap;
> + int saved_errno = errno;
>
> if (errp == NULL) {
> return;
> @@ -41,6 +42,8 @@ void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...)
> err->err_class = err_class;
>
> *errp = err;
> +
> + errno = saved_errno;
> }
>
> void error_set_errno(Error **errp, int os_errno, ErrorClass err_class,
> @@ -49,6 +52,7 @@ void error_set_errno(Error **errp, int os_errno, ErrorClass err_class,
> Error *err;
> char *msg1;
> va_list ap;
> + int saved_errno = errno;
>
> if (errp == NULL) {
> return;
> @@ -69,6 +73,8 @@ void error_set_errno(Error **errp, int os_errno, ErrorClass err_class,
> err->err_class = err_class;
>
> *errp = err;
> +
> + errno = saved_errno;
> }
>
> void error_setg_file_open(Error **errp, int os_errno, const char *filename)
> --
> 1.8.4.2
>
>
Yes this look better than trying to fix all callers.
Reviewed-by: Benoit Canet <benoit@irqsave.net
next prev parent reply other threads:[~2013-11-07 19:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-07 19:10 [Qemu-devel] [PATCH] util/error: Save errno from clobbering Max Reitz
2013-11-07 19:18 ` Benoît Canet [this message]
2013-11-07 20:14 ` Eric Blake
2013-11-08 14:54 ` 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=20131107191845.GG2921@irqsave.net \
--to=benoit.canet@irqsave.net \
--cc=kwolf@redhat.com \
--cc=mreitz@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.