diff options
author | Markus Armbruster <armbru@redhat.com> | 2015-09-11 16:51:42 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2015-09-18 14:38:08 +0200 |
commit | a29a37b994ca3c5a1d39fa0e8934f7e0f2cf57ef (patch) | |
tree | f370acbbace6189dedc5f3b000c4307a07af663e /util | |
parent | 4f966768acd1d677d24d60a01c160c18a09cce80 (diff) | |
download | qemu-a29a37b994ca3c5a1d39fa0e8934f7e0f2cf57ef.zip qemu-a29a37b994ca3c5a1d39fa0e8934f7e0f2cf57ef.tar.gz qemu-a29a37b994ca3c5a1d39fa0e8934f7e0f2cf57ef.tar.bz2 |
error: New error_fatal
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>
Diffstat (limited to 'util')
-rw-r--r-- | util/error.c | 34 |
1 files changed, 21 insertions, 13 deletions
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); } } |