From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35836) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrLpG-0006Si-9O for qemu-devel@nongnu.org; Mon, 02 Jun 2014 02:34:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrLp8-0005Ay-PT for qemu-devel@nongnu.org; Mon, 02 Jun 2014 02:34:30 -0400 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:43977) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrLp7-00054I-W0 for qemu-devel@nongnu.org; Mon, 02 Jun 2014 02:34:22 -0400 Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 2 Jun 2014 16:34:16 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 83ACC2CE8050 for ; Mon, 2 Jun 2014 16:34:14 +1000 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s526XvoP5767552 for ; Mon, 2 Jun 2014 16:33:59 +1000 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s526YCVc008843 for ; Mon, 2 Jun 2014 16:34:12 +1000 From: Alexey Kardashevskiy Date: Mon, 2 Jun 2014 16:34:10 +1000 Message-Id: <1401690850-24854-1-git-send-email-aik@ozlabs.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH v2] trace: Replace fprintf with error_report and print location List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Alexey Kardashevskiy , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= , Stefan Hajnoczi This replaces fprintf(stderr) with error_report. This moves local variables to the beginning of the function to comply with QEMU's coding style. Suggested-by: LluĂ­s Vilanova Signed-off-by: Alexey Kardashevskiy --- Changes: v2: * polished commit log --- trace/control.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/trace/control.c b/trace/control.c index 4aa02cf..4ee2bd2 100644 --- a/trace/control.c +++ b/trace/control.c @@ -8,7 +8,7 @@ */ #include "trace/control.h" - +#include "qemu/error-report.h" TraceEvent *trace_event_name(const char *name) { @@ -81,18 +81,24 @@ TraceEvent *trace_event_pattern(const char *pat, TraceEvent *ev) void trace_backend_init_events(const char *fname) { + Location loc; + FILE *fp; + char line_buf[1024]; + size_t line_idx = 0; + if (fname == NULL) { return; } - FILE *fp = fopen(fname, "r"); + loc_push_none(&loc); + loc_set_file(fname, 0); + fp = fopen(fname, "r"); if (!fp) { - fprintf(stderr, "error: could not open trace events file '%s': %s\n", - fname, strerror(errno)); + error_report("%s", strerror(errno)); exit(1); } - char line_buf[1024]; while (fgets(line_buf, sizeof(line_buf), fp)) { + loc_set_file(fname, ++line_idx); size_t len = strlen(line_buf); if (len > 1) { /* skip empty lines */ line_buf[len - 1] = '\0'; @@ -111,13 +117,11 @@ void trace_backend_init_events(const char *fname) } else { TraceEvent *ev = trace_event_name(line_ptr); if (ev == NULL) { - fprintf(stderr, - "WARNING: trace event '%s' does not exist\n", - line_ptr); + error_report("WARNING: trace event '%s' does not exist", + line_ptr); } else if (!trace_event_get_state_static(ev)) { - fprintf(stderr, - "WARNING: trace event '%s' is not traceable\n", - line_ptr); + error_report("WARNING: trace event '%s' is not traceable\n", + line_ptr); } else { trace_event_set_state_dynamic(ev, enable); } @@ -125,8 +129,9 @@ void trace_backend_init_events(const char *fname) } } if (fclose(fp) != 0) { - fprintf(stderr, "error: closing file '%s': %s\n", - fname, strerror(errno)); + loc_set_file(fname, 0); + error_report("%s", strerror(errno)); exit(1); } + loc_pop(&loc); } -- 2.0.0