From patchwork Tue Feb 2 16:13:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Llu=C3=ADs_Vilanova?= X-Patchwork-Id: 8191701 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9E7409FBE9 for ; Tue, 2 Feb 2016 16:14:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0378F201EC for ; Tue, 2 Feb 2016 16:14:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 44E0F202F0 for ; Tue, 2 Feb 2016 16:14:23 +0000 (UTC) Received: from localhost ([::1]:57921 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQdaw-0002GP-I9 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 02 Feb 2016 11:14:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52962) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQdai-0002Ct-4j for qemu-devel@nongnu.org; Tue, 02 Feb 2016 11:14:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQdaf-0005WN-BH for qemu-devel@nongnu.org; Tue, 02 Feb 2016 11:14:08 -0500 Received: from roura.ac.upc.edu ([147.83.33.10]:58652 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQdae-0005WA-Ul for qemu-devel@nongnu.org; Tue, 02 Feb 2016 11:14:05 -0500 Received: from gw-2.ac.upc.es (gw-2.ac.upc.es [147.83.30.8]) by roura.ac.upc.es (8.13.8/8.13.8) with ESMTP id u12GDx1C002537; Tue, 2 Feb 2016 17:13:59 +0100 Received: from localhost (unknown [84.88.51.85]) by gw-2.ac.upc.es (Postfix) with ESMTPSA id F36BC341; Tue, 2 Feb 2016 17:13:58 +0100 (CET) From: =?utf-8?b?TGx1w61z?= Vilanova To: qemu-devel@nongnu.org Date: Tue, 2 Feb 2016 17:13:58 +0100 Message-Id: <145442963860.1539.7135815311391731257.stgit@localhost> X-Mailer: git-send-email 2.7.0 In-Reply-To: <145442963048.1539.13602468921796488810.stgit@localhost> References: <145442963048.1539.13602468921796488810.stgit@localhost> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-MIME-Autoconverted: from 8bit to quoted-printable by roura.ac.upc.es id u12GDx1C002537 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 147.83.33.10 Cc: Thomas Huth , Stefan Hajnoczi , "Dr . David Alan Gilbert" , Markus Armbruster , David Gibson Subject: [Qemu-devel] [PATCH v6 1/5] util: Introduce error reporting functions with fatal/abort X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Provide two lean functions to report error messages that fatal/abort QEMU. Signed-off-by: LluĂ­s Vilanova --- include/qemu/error-report.h | 19 +++++++++++++++++++ util/qemu-error.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h index 7ab2355..6c2f142 100644 --- a/include/qemu/error-report.h +++ b/include/qemu/error-report.h @@ -43,4 +43,23 @@ void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2); const char *error_get_progname(void); extern bool enable_timestamp_msg; +/* Report message and exit with error */ +void QEMU_NORETURN error_vreport_fatal(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); +void QEMU_NORETURN error_report_fatal(const char *fmt, ...) GCC_FMT_ATTR(1, 2); +/* Report message with caller location and abort */ +#define error_vreport_abort(fmt, ap) \ + do { \ + error_report_abort_caller_internal(__FILE__, __LINE__, __func__); \ + error_vreport_abort_internal(fmt, ap); \ + } while (0) +#define error_report_abort(fmt, ...) \ + do { \ + error_report_abort_caller_internal(__FILE__, __LINE__, __func__); \ + error_report_abort_internal(fmt, ##__VA_ARGS__); \ + } while (0) + +void error_report_abort_caller_internal(const char *file, int line, const char *func); +void QEMU_NORETURN error_vreport_abort_internal(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); +void QEMU_NORETURN error_report_abort_internal(const char *fmt, ...) GCC_FMT_ATTR(1, 2); + #endif diff --git a/util/qemu-error.c b/util/qemu-error.c index ecf5708..3de002b 100644 --- a/util/qemu-error.c +++ b/util/qemu-error.c @@ -237,3 +237,36 @@ void error_report(const char *fmt, ...) error_vreport(fmt, ap); va_end(ap); } + +void error_vreport_fatal(const char *fmt, va_list ap) +{ + error_vreport(fmt, ap); + exit(1); +} + +void error_report_fatal(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + error_vreport_fatal(fmt, ap); + va_end(ap); +} + +void error_report_abort_caller_internal(const char *file, int line, const char *func) +{ + error_report("Unexpected error in %s() at %s:%d:", func, file, line); +} + +void error_vreport_abort_internal(const char *fmt, va_list ap) +{ + error_vreport(fmt, ap); + abort(); +} + +void error_report_abort_internal(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + error_vreport_abort_internal(fmt, ap); + va_end(ap); +}