qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com, armbru@redhat.com
Subject: [Qemu-devel] [PATCH 1/6] error: add error_set_errno and error_setg_errno
Date: Fri, 19 Oct 2012 11:28:00 -0300	[thread overview]
Message-ID: <1350656885-6485-2-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1350656885-6485-1-git-send-email-lcapitulino@redhat.com>

From: Paolo Bonzini <pbonzini@redhat.com>

These functions help maintaining homogeneous formatting of error
messages that include strerror values.

Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---

This patch is also in a pull request from Paolo to Anthony. We can just merge
it along with this series and git will do the right thing when merging it in
master.

 error.c | 28 ++++++++++++++++++++++++++++
 error.h |  9 +++++++++
 2 files changed, 37 insertions(+)

diff --git a/error.c b/error.c
index 1f05fc4..128d88c 100644
--- a/error.c
+++ b/error.c
@@ -43,6 +43,34 @@ void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...)
     *errp = err;
 }
 
+void error_set_errno(Error **errp, int os_errno, ErrorClass err_class,
+                     const char *fmt, ...)
+{
+    Error *err;
+    char *msg1;
+    va_list ap;
+
+    if (errp == NULL) {
+        return;
+    }
+    assert(*errp == NULL);
+
+    err = g_malloc0(sizeof(*err));
+
+    va_start(ap, fmt);
+    msg1 = g_strdup_vprintf(fmt, ap);
+    if (os_errno != 0) {
+        err->msg = g_strdup_printf("%s: %s", msg1, strerror(os_errno));
+        g_free(msg1);
+    } else {
+        err->msg = msg1;
+    }
+    va_end(ap);
+    err->err_class = err_class;
+
+    *errp = err;
+}
+
 Error *error_copy(const Error *err)
 {
     Error *err_new;
diff --git a/error.h b/error.h
index da7fed3..4d52e73 100644
--- a/error.h
+++ b/error.h
@@ -30,10 +30,19 @@ typedef struct Error Error;
 void error_set(Error **err, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(3, 4);
 
 /**
+ * Set an indirect pointer to an error given a ErrorClass value and a
+ * printf-style human message, followed by a strerror() string if
+ * @os_error is not zero.
+ */
+void error_set_errno(Error **err, int os_error, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(4, 5);
+
+/**
  * Same as error_set(), but sets a generic error
  */
 #define error_setg(err, fmt, ...) \
     error_set(err, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__)
+#define error_setg_errno(err, os_error, fmt, ...) \
+    error_set_errno(err, os_error, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__)
 
 /**
  * Returns true if an indirect pointer to an error is pointing to a valid
-- 
1.7.12.315.g682ce8b

  reply	other threads:[~2012-10-19 14:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-19 14:27 [Qemu-devel] [PATCH v2 0/6] block: bdrv_img_create(): propagate errors Luiz Capitulino
2012-10-19 14:28 ` Luiz Capitulino [this message]
2012-10-19 14:28 ` [Qemu-devel] [PATCH 2/6] block: bdrv_img_create(): add Error ** argument Luiz Capitulino
2012-10-19 14:28 ` [Qemu-devel] [PATCH 3/6] qemu-img: img_create(): pass Error object to bdrv_img_create() Luiz Capitulino
2012-10-19 14:28 ` [Qemu-devel] [PATCH 4/6] qemu-img: img_create(): drop unneeded goto and ret variable Luiz Capitulino
2012-10-19 14:28 ` [Qemu-devel] [PATCH 5/6] qmp: qmp_transaction(): pass Error object to bdrv_img_create() Luiz Capitulino
2012-10-19 14:28 ` [Qemu-devel] [PATCH 6/6] block: bdrv_img_create(): drop unused error handling code Luiz Capitulino
2012-11-02 13:25 ` [Qemu-devel] [PATCH v2 0/6] block: bdrv_img_create(): propagate errors Luiz Capitulino
2012-11-02 13:40   ` Kevin Wolf
2012-11-02 13:42     ` Luiz Capitulino
2012-11-29 16:34       ` Luiz Capitulino
2012-11-30 11:39         ` Kevin Wolf
2012-11-30 11:44           ` Luiz Capitulino

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=1350656885-6485-2-git-send-email-lcapitulino@redhat.com \
    --to=lcapitulino@redhat.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.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).