diff options
| author | Peter Maydell | 2015-09-18 15:41:53 +0200 |
|---|---|---|
| committer | Peter Maydell | 2015-09-18 15:41:53 +0200 |
| commit | ffa4822c015d5670ef6a2239f3cbd2ff2cec57de (patch) | |
| tree | daef772c57a4e47fffbcd5ff1b03cee338d63220 /util | |
| parent | Merge remote-tracking branch 'remotes/lalrae/tags/mips-20150918' into staging (diff) | |
| parent | memory: Fix bad error handling in memory_region_init_ram_ptr() (diff) | |
| download | qemu-ffa4822c015d5670ef6a2239f3cbd2ff2cec57de.tar.gz qemu-ffa4822c015d5670ef6a2239f3cbd2ff2cec57de.tar.xz qemu-ffa4822c015d5670ef6a2239f3cbd2ff2cec57de.zip | |
Merge remote-tracking branch 'remotes/armbru/tags/pull-error-2015-09-18' into staging
Error reporting patches
# gpg: Signature made Fri 18 Sep 2015 13:42:49 BST using RSA key ID EB918653
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>"
# gpg: aka "Markus Armbruster <armbru@pond.sub.org>"
* remotes/armbru/tags/pull-error-2015-09-18:
memory: Fix bad error handling in memory_region_init_ram_ptr()
loader: Fix memory_region_init_resizeable_ram() error handling
Fix bad error handling after memory_region_init_ram()
error: New error_fatal
MAINTAINERS: Add "Error reporting" entry
error: Copy location information in error_copy()
hmp: Allow for error message hints on HMP
error: only prepend timestamp on stderr
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'util')
| -rw-r--r-- | util/error.c | 69 | ||||
| -rw-r--r-- | util/qemu-error.c | 2 | ||||
| -rw-r--r-- | util/qemu-option.c | 11 |
3 files changed, 61 insertions, 21 deletions
diff --git a/util/error.c b/util/error.c index cdb726ce81..8b86490ba1 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. @@ -20,16 +22,24 @@ struct Error ErrorClass err_class; const char *src, *func; int line; + GString *hint; }; 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, @@ -51,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; @@ -115,6 +122,28 @@ void error_setg_file_open_internal(Error **errp, "Could not open '%s'", filename); } +void error_append_hint(Error **errp, const char *fmt, ...) +{ + va_list ap; + int saved_errno = errno; + Error *err; + + if (!errp) { + return; + } + err = *errp; + assert(err && errp != &error_abort); + + if (!err->hint) { + err->hint = g_string_new(NULL); + } + va_start(ap, fmt); + g_string_append_vprintf(err->hint, fmt, ap); + va_end(ap); + + errno = saved_errno; +} + #ifdef _WIN32 void error_setg_win32_internal(Error **errp, @@ -151,6 +180,12 @@ Error *error_copy(const Error *err) err_new = g_malloc0(sizeof(*err)); err_new->msg = g_strdup(err->msg); err_new->err_class = err->err_class; + err_new->src = err->src; + err_new->line = err->line; + err_new->func = err->func; + if (err->hint) { + err_new->hint = g_string_new(err->hint->str); + } return err_new; } @@ -168,6 +203,9 @@ const char *error_get_pretty(Error *err) void error_report_err(Error *err) { error_report("%s", error_get_pretty(err)); + if (err->hint) { + error_printf_unless_qmp("%s\n", err->hint->str); + } error_free(err); } @@ -175,17 +213,22 @@ void error_free(Error *err) { if (err) { g_free(err->msg); + if (err->hint) { + g_string_free(err->hint, true); + } g_free(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); } } diff --git a/util/qemu-error.c b/util/qemu-error.c index 77ea6c6145..c1574bb348 100644 --- a/util/qemu-error.c +++ b/util/qemu-error.c @@ -210,7 +210,7 @@ void error_vreport(const char *fmt, va_list ap) GTimeVal tv; gchar *timestr; - if (enable_timestamp_msg) { + if (enable_timestamp_msg && !cur_mon) { g_get_current_time(&tv); timestr = g_time_val_to_iso8601(&tv); error_printf("%s ", timestr); diff --git a/util/qemu-option.c b/util/qemu-option.c index b1fb57c0fc..a50eceae4a 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -205,10 +205,8 @@ void parse_option_size(const char *name, const char *value, break; default: error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, "a size"); -#if 0 /* conversion from qerror_report() to error_set() broke this: */ - error_printf_unless_qmp("You may use k, M, G or T suffixes for " - "kilobytes, megabytes, gigabytes and terabytes.\n"); -#endif + error_append_hint(errp, "You may use k, M, G or T suffixes for " + "kilobytes, megabytes, gigabytes and terabytes."); return; } } else { @@ -648,9 +646,8 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, if (!id_wellformed(id)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id", "an identifier"); -#if 0 /* conversion from qerror_report() to error_set() broke this: */ - error_printf_unless_qmp("Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.\n"); -#endif + error_append_hint(errp, "Identifiers consist of letters, digits, " + "'-', '.', '_', starting with a letter."); return NULL; } opts = qemu_opts_find(list, id); |
