* [Qemu-devel] [PATCH v2] trace: Replace fprintf with error_report and print location
@ 2014-06-02 6:34 Alexey Kardashevskiy
2014-06-04 11:05 ` Stefan Hajnoczi
0 siblings, 1 reply; 2+ messages in thread
From: Alexey Kardashevskiy @ 2014-06-02 6:34 UTC (permalink / raw)
To: qemu-devel; +Cc: Alexey Kardashevskiy, Lluís Vilanova, 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 <vilanova@ac.upc.edu>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH v2] trace: Replace fprintf with error_report and print location
2014-06-02 6:34 [Qemu-devel] [PATCH v2] trace: Replace fprintf with error_report and print location Alexey Kardashevskiy
@ 2014-06-04 11:05 ` Stefan Hajnoczi
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2014-06-04 11:05 UTC (permalink / raw)
To: Alexey Kardashevskiy; +Cc: qemu-devel, Stefan Hajnoczi, Lluís Vilanova
On Mon, Jun 02, 2014 at 04:34:10PM +1000, Alexey Kardashevskiy wrote:
> 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>
> ---
> Changes:
> v2:
> * polished commit log
> ---
> trace/control.c | 31 ++++++++++++++++++-------------
> 1 file changed, 18 insertions(+), 13 deletions(-)
Thanks, applied to my tracing tree:
https://github.com/stefanha/qemu/commits/tracing
Stefan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-06-04 11:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-02 6:34 [Qemu-devel] [PATCH v2] trace: Replace fprintf with error_report and print location Alexey Kardashevskiy
2014-06-04 11:05 ` Stefan Hajnoczi
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).