From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZd3F-00078U-2G for qemu-devel@nongnu.org; Tue, 16 Aug 2016 08:01:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bZd3B-0002A2-W2 for qemu-devel@nongnu.org; Tue, 16 Aug 2016 08:01:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60612) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZd3B-00029p-Qa for qemu-devel@nongnu.org; Tue, 16 Aug 2016 08:00:57 -0400 Date: Tue, 16 Aug 2016 19:53:51 +0800 From: Fam Zheng Message-ID: <20160816115351.GB27853@al.usersys.redhat.com> References: <1470901038-9409-1-git-send-email-peterx@redhat.com> <1470901038-9409-2-git-send-email-peterx@redhat.com> <87eg5p6kk0.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87eg5p6kk0.fsf@dusky.pond.sub.org> Subject: Re: [Qemu-devel] [PATCH 1/2] error-report: provide error_report_exit() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: Peter Xu , peter.maydell@linaro.org, qemu-devel@nongnu.org, pbonzini@redhat.com On Tue, 08/16 13:05, Markus Armbruster wrote: > Peter Xu writes: > > > There are many places in current QEMU codes that needs to print some > > error and then quit QEMU. Provide a macro for it. > > > > Also, one coccinelle script is added to convert existing cases to > > leverage this new macro. > > > > Signed-off-by: Peter Xu > > --- > > include/qemu/error-report.h | 8 ++++++++ > > scripts/coccinelle/error_report_exit.cocci | 13 +++++++++++++ > > 2 files changed, 21 insertions(+) > > create mode 100644 scripts/coccinelle/error_report_exit.cocci > > > > diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h > > index 499ec8b..c2d5059 100644 > > --- a/include/qemu/error-report.h > > +++ b/include/qemu/error-report.h > > @@ -13,6 +13,8 @@ > > #ifndef QEMU_ERROR_REPORT_H > > #define QEMU_ERROR_REPORT_H > > > > +#include > > + > > typedef struct Location { > > /* all members are private to qemu-error.c */ > > enum { LOC_NONE, LOC_CMDLINE, LOC_FILE } kind; > > @@ -36,6 +38,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_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2); > > + > > +#define error_report_exit(...) do { \ > > + error_report(__VA_ARGS__); \ > > + exit(1); \ > > + } while (0) > > + > > Let's call it error_report_fatal(), for consistency with error_fatal. Do we really need error_report_exit when we already have error_fatal? Fam > > Also, please make it a function, not a macro: > > void error_report_fatal(const char *fmt, ...) > { > va_list ap; > > va_start(ap, fmt); > error_vreport(fmt, ap); > va_end(ap); > exit(1); > } > > > const char *error_get_progname(void); > > extern bool enable_timestamp_msg; > > > > diff --git a/scripts/coccinelle/error_report_exit.cocci b/scripts/coccinelle/error_report_exit.cocci > > new file mode 100644 > > index 0000000..49f6c17 > > --- /dev/null > > +++ b/scripts/coccinelle/error_report_exit.cocci > > @@ -0,0 +1,13 @@ > > +@@ > > +expression list X; > > +@@ > > + > > +-error_report(X); > > ++error_report_exit(X); > > +-exit( > > +( > > +-1 > > +| > > +-EXIT_FAILURE > > +) > > +-); >