From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z57iQ-000101-FF for qemu-devel@nongnu.org; Wed, 17 Jun 2015 03:24:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z57iM-0001kn-A9 for qemu-devel@nongnu.org; Wed, 17 Jun 2015 03:24:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46571) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z57iM-0001kX-4l for qemu-devel@nongnu.org; Wed, 17 Jun 2015 03:24:50 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id D117BC1F0D for ; Wed, 17 Jun 2015 07:24:49 +0000 (UTC) Date: Wed, 17 Jun 2015 09:24:46 +0200 From: "Michael S. Tsirkin" Message-ID: <1434525861-21768-3-git-send-email-mst@redhat.com> References: <1434525861-21768-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1434525861-21768-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PATCH v2 2/3] error: allow local errors to trigger abort List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, armbru@redhat.com, dgilbert@redhat.com It's a common idiom: Error *local_err = NULL; .... foo(&local_err); ... if (local_err) { error_propagate(errp, local_err); return; } Unfortunately it means that call to foo(&local_err) will not abort even if errp is set to error_abort. Instead, we get an abort at error_propagate which is too late, that is, the quality of the stack trace is degraded in that it no longer pinpoints the actual cause of failure. To fix, add an API to check errp and set local_err to error_abort if errp is error_abort. Signed-off-by: Michael S. Tsirkin Reviewed-by: Eric Blake --- include/qapi/error.h | 5 +++++ util/error.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/include/qapi/error.h b/include/qapi/error.h index f44c451..8246a62 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -88,6 +88,11 @@ const char *error_get_pretty(Error *err); void error_report_err(Error *); /** + * Init a local error. It must be propagated to errp using error_propagate. + */ +Error *error_init_local(Error **errp); + +/** * Propagate an error to an indirect pointer to an error. This function will * always transfer ownership of the error reference and handles the case where * dst_err is NULL correctly. Errors after the first are discarded. diff --git a/util/error.c b/util/error.c index e10cb34..7f5b134 100644 --- a/util/error.c +++ b/util/error.c @@ -28,6 +28,11 @@ static bool error_is_abort(Error **errp) return errp && *errp == error_abort; } +Error *error_init_local(Error **errp) +{ + return error_is_abort(errp) ? *errp : NULL; +} + void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...) { Error *err; -- MST