From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41115) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a0w3K-0006Gu-LC for qemu-devel@nongnu.org; Mon, 23 Nov 2015 13:41:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a0w3G-00086c-20 for qemu-devel@nongnu.org; Mon, 23 Nov 2015 13:41:26 -0500 Received: from roura.ac.upc.edu ([147.83.33.10]:59863 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a0w3F-000863-OF for qemu-devel@nongnu.org; Mon, 23 Nov 2015 13:41:22 -0500 From: =?utf-8?b?TGx1w61z?= Vilanova Date: Mon, 23 Nov 2015 19:41:18 +0100 Message-Id: <144830407866.1693.583513653132678664.stgit@localhost> In-Reply-To: <144830407261.1693.6845199723252391860.stgit@localhost> References: <144830407261.1693.6845199723252391860.stgit@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 1/2] utils: Add warning messages List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Thomas Huth , Stefan Hajnoczi , Michael Roth , "Dr . David Alan Gilbert" , Markus Armbruster Adds a special error object that transforms error messages into immediately reported warnings. Signed-off-by: Llu=C3=ADs Vilanova --- include/qapi/error.h | 20 ++++++++++++++++++++ util/error.c | 37 +++++++++++++++++++++++++++---------- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/include/qapi/error.h b/include/qapi/error.h index 4d42cdc..9b7600c 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -57,6 +57,9 @@ * Call a function treating errors as fatal: * foo(arg, &error_fatal); * + * Call a function immediately showing all errors as warnings: + * foo(arg, &error_warn); + * * Receive an error and pass it on to the caller: * Error *err =3D NULL; * foo(arg, &err); @@ -108,6 +111,7 @@ ErrorClass error_get_class(const Error *err); * 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 &error_warn, print a suitable message. * 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, ... @@ -158,6 +162,7 @@ void error_setg_win32_internal(Error **errp, * abort(). * Else, if @dst_errp is &error_fatal, print a suitable message and * exit(1). + * Else, if @dst_errp is &error_warn, print a suitable message. * 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. @@ -218,12 +223,27 @@ void error_set_internal(Error **errp, =20 /* * Pass to error_setg() & friends to abort() on error. + * + * WARNING: Do _not_ use for errors that are (or can be) triggered by gu= est code + * (e.g., some unimplimented corner case in guest code translat= ion or + * device code). Otherwise that can be abused by guest code to + * terminate QEMU. */ extern Error *error_abort; =20 /* * Pass to error_setg() & friends to exit(1) on error. + * + * WARNING: Do _not_ use for errors that are (or can be) triggered by gu= est code + * (e.g., some unimplimented corner case in guest code translat= ion or + * device code). Otherwise that can be abused by guest code to + * terminate QEMU. */ extern Error *error_fatal; =20 +/* + * Pass to error_setg() & friends to immediately show an error as a warn= ing. + */ +extern Error *error_warn; + #endif diff --git a/util/error.c b/util/error.c index 80c89a2..85170e54 100644 --- a/util/error.c +++ b/util/error.c @@ -15,6 +15,7 @@ #include "qemu-common.h" #include "qapi/error.h" #include "qemu/error-report.h" +#include "qemu/timer.h" =20 struct Error { @@ -27,8 +28,9 @@ struct Error =20 Error *error_abort; Error *error_fatal; +Error *error_warn; =20 -static void error_handle_fatal(Error **errp, Error *err) +static bool error_handle_fatal(Error **errp, Error *err) { if (errp =3D=3D &error_abort) { fprintf(stderr, "Unexpected error in %s() at %s:%d:\n", @@ -40,6 +42,20 @@ static void error_handle_fatal(Error **errp, Error *er= r) error_report_err(err); exit(1); } + + if (errp =3D=3D &error_warn) { + /* cannot use error_report_err() because it adds newlines */ + error_report("warning: [%s() at %s:%d] %s", + err->func, err->src, err->line, err->msg); + if (err->hint) { + error_printf_unless_qmp("warning: [%s() at %s:%d] %s", + err->func, err->src, err->line, + err->hint->str); + } + return true; + } else { + return false; + } } =20 static void error_setv(Error **errp, @@ -61,10 +77,10 @@ static void error_setv(Error **errp, err->line =3D line; err->func =3D func; =20 - error_handle_fatal(errp, err); - *errp =3D err; - - errno =3D saved_errno; + if (!error_handle_fatal(errp, err)) { + *errp =3D err; + errno =3D saved_errno; + } } =20 void error_set_internal(Error **errp, @@ -232,10 +248,11 @@ void error_propagate(Error **dst_errp, Error *local= _err) if (!local_err) { return; } - error_handle_fatal(dst_errp, local_err); - if (dst_errp && !*dst_errp) { - *dst_errp =3D local_err; - } else { - error_free(local_err); + if (!error_handle_fatal(dst_errp, local_err)) { + if (dst_errp && !*dst_errp) { + *dst_errp =3D local_err; + } else { + error_free(local_err); + } } }