qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 5/8] error: New error_fatal
Date: Fri, 18 Sep 2015 15:22:51 +0200	[thread overview]
Message-ID: <1442582574-14275-6-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1442582574-14275-1-git-send-email-armbru@redhat.com>

Similar to error_abort, but doesn't report where the error was
created, and terminates the process with exit(1) rather than abort().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1441983105-26376-2-git-send-email-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
---
 include/qapi/error.h | 11 +++++++++++
 util/error.c         | 34 +++++++++++++++++++++-------------
 2 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/include/qapi/error.h b/include/qapi/error.h
index d7878c3..c69dddb 100644
--- a/include/qapi/error.h
+++ b/include/qapi/error.h
@@ -50,6 +50,9 @@
  * Call a function aborting on errors:
  *     foo(arg, &error_abort);
  *
+ * Call a function treating errors as fatal:
+ *     foo(arg, &error_fatal);
+ *
  * Receive an error and pass it on to the caller:
  *     Error *err = NULL;
  *     foo(arg, &err);
@@ -100,6 +103,7 @@ ErrorClass error_get_class(const Error *err);
  * If @errp is NULL, the error is ignored.  Don't bother creating one
  * then.
  * If @errp is &error_abort, print a suitable message and abort().
+ * If @errp is &error_fatal, print a suitable message and exit(1).
  * If @errp is anything else, *@errp must be NULL.
  * The new error's class is ERROR_CLASS_GENERIC_ERROR, and its
  * human-readable error message is made from printf-style @fmt, ...
@@ -148,6 +152,8 @@ void error_setg_win32_internal(Error **errp,
  * error object.
  * Else, if @dst_errp is &error_abort, print a suitable message and
  * abort().
+ * Else, if @dst_errp is &error_fatal, print a suitable message and
+ * exit(1).
  * Else, if @dst_errp already contains an error, ignore this one: free
  * the error object.
  * Else, move the error object from @local_err to *@dst_errp.
@@ -206,4 +212,9 @@ void error_set_internal(Error **errp,
  */
 extern Error *error_abort;
 
+/*
+ * Pass to error_setg() & friends to exit(1) on error.
+ */
+extern Error *error_fatal;
+
 #endif
diff --git a/util/error.c b/util/error.c
index b1eb8a2..8b86490 100644
--- a/util/error.c
+++ b/util/error.c
@@ -2,9 +2,11 @@
  * QEMU Error Objects
  *
  * Copyright IBM, Corp. 2011
+ * Copyright (C) 2011-2015 Red Hat, Inc.
  *
  * Authors:
  *  Anthony Liguori   <aliguori@us.ibm.com>
+ *  Markus Armbruster <armbru@redhat.com>,
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.  See
  * the COPYING.LIB file in the top-level directory.
@@ -24,13 +26,20 @@ struct Error
 };
 
 Error *error_abort;
+Error *error_fatal;
 
-static void error_do_abort(Error *err)
+static void error_handle_fatal(Error **errp, Error *err)
 {
-    fprintf(stderr, "Unexpected error in %s() at %s:%d:\n",
-            err->func, err->src, err->line);
-    error_report_err(err);
-    abort();
+    if (errp == &error_abort) {
+        fprintf(stderr, "Unexpected error in %s() at %s:%d:\n",
+                err->func, err->src, err->line);
+        error_report_err(err);
+        abort();
+    }
+    if (errp == &error_fatal) {
+        error_report_err(err);
+        exit(1);
+    }
 }
 
 static void error_setv(Error **errp,
@@ -52,10 +61,7 @@ static void error_setv(Error **errp,
     err->line = line;
     err->func = func;
 
-    if (errp == &error_abort) {
-        error_do_abort(err);
-    }
-
+    error_handle_fatal(errp, err);
     *errp = err;
 
     errno = saved_errno;
@@ -216,11 +222,13 @@ void error_free(Error *err)
 
 void error_propagate(Error **dst_errp, Error *local_err)
 {
-    if (local_err && dst_errp == &error_abort) {
-        error_do_abort(local_err);
-    } else if (dst_errp && !*dst_errp) {
+    if (!local_err) {
+        return;
+    }
+    error_handle_fatal(dst_errp, local_err);
+    if (dst_errp && !*dst_errp) {
         *dst_errp = local_err;
-    } else if (local_err) {
+    } else {
         error_free(local_err);
     }
 }
-- 
2.4.3

  parent reply	other threads:[~2015-09-18 13:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-18 13:22 [Qemu-devel] [PULL 0/8] Error reporting patches Markus Armbruster
2015-09-18 13:22 ` [Qemu-devel] [PULL 1/8] error: only prepend timestamp on stderr Markus Armbruster
2015-09-18 13:22 ` [Qemu-devel] [PULL 2/8] hmp: Allow for error message hints on HMP Markus Armbruster
2015-09-22 15:23   ` Kevin Wolf
2015-09-22 17:02     ` Eric Blake
2015-09-22 23:02       ` [Qemu-devel] [Qemu-block] " John Snow
2015-09-18 13:22 ` [Qemu-devel] [PULL 3/8] error: Copy location information in error_copy() Markus Armbruster
2015-09-18 13:22 ` [Qemu-devel] [PULL 4/8] MAINTAINERS: Add "Error reporting" entry Markus Armbruster
2015-09-18 13:22 ` Markus Armbruster [this message]
2015-09-18 13:22 ` [Qemu-devel] [PULL 6/8] Fix bad error handling after memory_region_init_ram() Markus Armbruster
2015-09-18 13:22 ` [Qemu-devel] [PULL 7/8] loader: Fix memory_region_init_resizeable_ram() error handling Markus Armbruster
2015-09-18 13:22 ` [Qemu-devel] [PULL 8/8] memory: Fix bad error handling in memory_region_init_ram_ptr() Markus Armbruster
2015-09-18 15:57 ` [Qemu-devel] [PULL 0/8] Error reporting patches 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=1442582574-14275-6-git-send-email-armbru@redhat.com \
    --to=armbru@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).