From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wu1Qi-0007u5-FX for qemu-devel@nongnu.org; Mon, 09 Jun 2014 11:24:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wu1Qd-0007Ii-FX for qemu-devel@nongnu.org; Mon, 09 Jun 2014 11:24:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15189) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wu1Qd-0007Ia-7B for qemu-devel@nongnu.org; Mon, 09 Jun 2014 11:24:07 -0400 From: Stefan Hajnoczi Date: Mon, 9 Jun 2014 17:23:49 +0200 Message-Id: <1402327429-20941-6-git-send-email-stefanha@redhat.com> In-Reply-To: <1402327429-20941-1-git-send-email-stefanha@redhat.com> References: <1402327429-20941-1-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 5/5] 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 , Peter Maydell , Stefan Hajnoczi From: Alexey Kardashevskiy 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=C3=ADs Vilanova Signed-off-by: Alexey Kardashevskiy Signed-off-by: Stefan Hajnoczi --- trace/control.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/trace/control.c b/trace/control.c index 45e6604..9631a40 100644 --- a/trace/control.c +++ b/trace/control.c @@ -14,7 +14,7 @@ #ifdef CONFIG_TRACE_FTRACE #include "trace/ftrace.h" #endif - +#include "qemu/error-report.h" =20 TraceEvent *trace_event_name(const char *name) { @@ -100,18 +100,24 @@ void trace_print_events(FILE *stream, fprintf_funct= ion stream_printf) =20 static void trace_init_events(const char *fname) { + Location loc; + FILE *fp; + char line_buf[1024]; + size_t line_idx =3D 0; + if (fname =3D=3D NULL) { return; } =20 - FILE *fp =3D fopen(fname, "r"); + loc_push_none(&loc); + loc_set_file(fname, 0); + fp =3D 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 =3D strlen(line_buf); if (len > 1) { /* skip empty lines */ line_buf[len - 1] =3D '\0'; @@ -130,13 +136,11 @@ static void trace_init_events(const char *fname) } else { TraceEvent *ev =3D trace_event_name(line_ptr); if (ev =3D=3D NULL) { - fprintf(stderr, - "WARNING: trace event '%s' does not exist\n"= , - line_ptr); + error_report("WARNING: trace event '%s' does not exi= st", + 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 trace= able\n", + line_ptr); } else { trace_event_set_state_dynamic(ev, enable); } @@ -144,10 +148,11 @@ static void trace_init_events(const char *fname) } } if (fclose(fp) !=3D 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); } =20 bool trace_init_backends(const char *events, const char *file) --=20 1.9.3