From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>,
Peter Maydell <peter.maydell@linaro.org>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL 5/5] trace: Replace fprintf with error_report and print location
Date: Mon, 9 Jun 2014 17:23:49 +0200 [thread overview]
Message-ID: <1402327429-20941-6-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1402327429-20941-1-git-send-email-stefanha@redhat.com>
From: Alexey Kardashevskiy <aik@ozlabs.ru>
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 <vilanova@ac.upc.edu>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
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"
TraceEvent *trace_event_name(const char *name)
{
@@ -100,18 +100,24 @@ void trace_print_events(FILE *stream, fprintf_function stream_printf)
static void trace_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';
@@ -130,13 +136,11 @@ static void trace_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);
}
@@ -144,10 +148,11 @@ static void trace_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);
}
bool trace_init_backends(const char *events, const char *file)
--
1.9.3
next prev parent reply other threads:[~2014-06-09 15:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-09 15:23 [Qemu-devel] [PULL v2 0/5] Tracing pull request Stefan Hajnoczi
2014-06-09 15:23 ` [Qemu-devel] [PULL 1/5] trace: add pid field to simpletrace record Stefan Hajnoczi
2014-06-09 15:23 ` [Qemu-devel] [PULL 2/5] simpletrace: add support for trace record pid field Stefan Hajnoczi
2014-06-09 15:23 ` [Qemu-devel] [PULL 3/5] trace: Replace error with warning if event is not defined Stefan Hajnoczi
2014-06-09 15:23 ` [Qemu-devel] [PULL 4/5] trace: Multi-backend tracing Stefan Hajnoczi
2014-06-16 9:58 ` Peter Maydell
2014-06-09 15:23 ` Stefan Hajnoczi [this message]
2014-06-09 16:03 ` [Qemu-devel] [PULL v2 0/5] Tracing pull request Peter Maydell
-- strict thread matches above, loose matches on Subject: below --
2014-06-09 13:45 [Qemu-devel] [PULL 0/5] Tracing patches Stefan Hajnoczi
2014-06-09 13:45 ` [Qemu-devel] [PULL 5/5] trace: Replace fprintf with error_report and print location Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1402327429-20941-6-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=aik@ozlabs.ru \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).