From 97f40301f1dc3a3658427d1e9d964007b6f5673b Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Wed, 12 Jul 2017 06:57:36 -0700 Subject: error: Functions to report warnings and informational messages Add warn_report(), warn_vreport() for reporting warnings, and info_report(), info_vreport() for informational messages. These are implemented them with a helper function factored out of error_vreport(), suitably generalized. This patch makes no changes to the output of the original error_report() function. Signed-off-by: Alistair Francis Reviewed-by: Markus Armbruster Message-Id: Signed-off-by: Markus Armbruster --- include/qemu/error-report.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include') diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h index 3001865896..e1c8ae1a52 100644 --- a/include/qemu/error-report.h +++ b/include/qemu/error-report.h @@ -35,8 +35,15 @@ void error_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2); void error_vprintf_unless_qmp(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); 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 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 warn_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2); +void info_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2); + const char *error_get_progname(void); extern bool enable_timestamp_msg; -- cgit v1.2.3-55-g7522 From e43ead1d0b9c467af4a2af8f5177316a0ccb5602 Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Wed, 12 Jul 2017 06:57:52 -0700 Subject: error: Implement the warn and free Error functions Implement warn_report_err() and warn_reportf_err() functions which are the same as the error_report_err() and error_reportf_err() functions except report a warning instead of an error. Signed-off-by: Alistair Francis Reviewed-by: Markus Armbruster Message-Id: <276ff93eadc0b01b8243cc61ffc331f77922c0d0.1499866456.git.alistair.francis@xilinx.com> Signed-off-by: Markus Armbruster --- include/qapi/error.h | 11 +++++++++++ scripts/checkpatch.pl | 1 + util/error.c | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+) (limited to 'include') diff --git a/include/qapi/error.h b/include/qapi/error.h index 7e532d00e9..af53b34410 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -266,11 +266,22 @@ void error_free(Error *err); */ void error_free_or_abort(Error **errp); +/* + * Convenience function to warn_report() and free @err. + */ +void warn_report_err(Error *err); + /* * Convenience function to error_report() and free @err. */ void error_report_err(Error *err); +/* + * Convenience function to error_prepend(), warn_report() and free @err. + */ +void warn_reportf_err(Error *err, const char *fmt, ...) + GCC_FMT_ATTR(2, 3); + /* * Convenience function to error_prepend(), error_report() and free @err. */ diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 9287cc5886..4e91122813 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2533,6 +2533,7 @@ sub process { error_setg_file_open| error_set| error_prepend| + warn_reportf_err| error_reportf_err| error_vreport| warn_vreport| diff --git a/util/error.c b/util/error.c index 020b86b9f0..3efdd69162 100644 --- a/util/error.c +++ b/util/error.c @@ -232,6 +232,15 @@ void error_report_err(Error *err) error_free(err); } +void warn_report_err(Error *err) +{ + warn_report("%s", error_get_pretty(err)); + if (err->hint) { + error_printf_unless_qmp("%s", err->hint->str); + } + error_free(err); +} + void error_reportf_err(Error *err, const char *fmt, ...) { va_list ap; @@ -242,6 +251,17 @@ void error_reportf_err(Error *err, const char *fmt, ...) error_report_err(err); } + +void warn_reportf_err(Error *err, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + error_vprepend(&err, fmt, ap); + va_end(ap); + warn_report_err(err); +} + void error_free(Error *err) { if (err) { -- cgit v1.2.3-55-g7522