From patchwork Thu Apr 26 16:53:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Jackson X-Patchwork-Id: 905257 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=eu.citrix.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40X3R957l7z9ryr for ; Fri, 27 Apr 2018 03:07:49 +1000 (AEST) Received: from localhost ([::1]:43602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBkN1-0000wu-QC for incoming@patchwork.ozlabs.org; Thu, 26 Apr 2018 13:07:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBkAC-0006jN-Gg for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBkA8-0001SN-Mz for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:32 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:34814) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fBkA8-0001Rn-DX for qemu-devel@nongnu.org; Thu, 26 Apr 2018 12:54:28 -0400 X-IronPort-AV: E=Sophos;i="5.49,330,1520899200"; d="scan'208";a="52864866" From: Ian Jackson To: Date: Thu, 26 Apr 2018 17:53:27 +0100 Message-ID: <1524761612-5307-3-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com> References: <1524761612-5307-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [RFC PATCH 2/7] error reporting: Provide error_report_errno (and error_vreport_errno) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , =?utf-8?q?Philippe_Mathieu-Da?= =?utf-8?q?ud=C3=A9?= , Alistair Francis Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This will let us replace a lot of open coded calls to perror, strerror, etc. No callers yet so no functional change. Signed-off-by: Ian Jackson --- include/qemu/error-report.h | 2 ++ util/qemu-error.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h index e1c8ae1..2b29678 100644 --- a/include/qemu/error-report.h +++ b/include/qemu/error-report.h @@ -37,10 +37,12 @@ void error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2); void error_set_progname(const char *argv0); void error_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); +void error_vreport_errno(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); void warn_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); void info_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2); +void error_report_errno(const char *fmt, ...) GCC_FMT_ATTR(1, 2); void warn_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2); void info_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2); diff --git a/util/qemu-error.c b/util/qemu-error.c index 9acc4b5..428c762 100644 --- a/util/qemu-error.c +++ b/util/qemu-error.c @@ -245,6 +245,18 @@ void error_vreport(const char *fmt, va_list ap) } /* + * Print an error message to current monitor if we have one, else to stderr. + * Format arguments like vsprintf(). The resulting message should be + * a single phrase, with no newline or trailing punctuation. + * Prepend the current location and append ": " strerror(errno) "\n". + * It's wrong to call this in a QMP monitor. Use error_setg() there. + */ +void error_vreport_errno(const char *fmt, va_list ap) +{ + vreport(REPORT_TYPE_ERROR, errno, fmt, ap); +} + +/* * Print a warning message to current monitor if we have one, else to stderr. * Format arguments like vsprintf(). The resulting message should be * a single phrase, with no newline or trailing punctuation. @@ -286,6 +298,22 @@ void error_report(const char *fmt, ...) } /* + * Print an error message to current monitor if we have one, else to stderr. + * Format arguments like sprintf(). The resulting message should be + * a single phrase, with no newline or trailing punctuation. + * Prepend the current location and append ": " strerror(errno) "\n". + * It's wrong to call this in a QMP monitor. Use error_setg() there. + */ +void error_report_errno(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vreport(REPORT_TYPE_ERROR, errno, fmt, ap); + va_end(ap); +} + +/* * Print a warning message to current monitor if we have one, else to stderr. * Format arguments like sprintf(). The resulting message should be a * single phrase, with no newline or trailing punctuation.