qemu-ga: guest_suspend(): improve error reporting
[qemu/ar7.git] / trace / control.c
blobbe05efb99b847bcd479892923ab643bf71f21ec8
1 /*
2 * Interface for configuring and controlling the state of tracing events.
4 * Copyright (C) 2011 LluĂ­s Vilanova <vilanova@ac.upc.edu>
6 * This work is licensed under the terms of the GNU GPL, version 2. See
7 * the COPYING file in the top-level directory.
8 */
10 #include "trace/control.h"
13 void trace_backend_init_events(const char *fname)
15 int ret;
17 if (fname == NULL) {
18 return;
21 FILE *fp = fopen(fname, "r");
22 if (!fp) {
23 fprintf(stderr, "error: could not open trace events file '%s': %s\n",
24 fname, strerror(errno));
25 exit(1);
27 char line_buf[1024];
28 while (fgets(line_buf, sizeof(line_buf), fp)) {
29 size_t len = strlen(line_buf);
30 if (len > 1) { /* skip empty lines */
31 line_buf[len - 1] = '\0';
32 if ('#' == line_buf[0]) { /* skip commented lines */
33 continue;
35 if ('-' == line_buf[0]) {
36 ret = trace_event_set_state(line_buf+1, false);
37 } else {
38 ret = trace_event_set_state(line_buf, true);
40 if (!ret) {
41 fprintf(stderr,
42 "error: trace event '%s' does not exist\n", line_buf);
43 exit(1);
47 if (fclose(fp) != 0) {
48 fprintf(stderr, "error: closing file '%s': %s\n",
49 fname, strerror(errno));
50 exit(1);