1 /* 2 * Interface for configuring and controlling the state of tracing events. 3 * 4 * Copyright (C) 2011 Lluís Vilanova <vilanova@ac.upc.edu> 5 * 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 */ 9 10 #include "trace/control.h" 11 12 13 void trace_backend_init_events(const char *fname) 14 { 15 int ret; 16 17 if (fname == NULL) { 18 return; 19 } 20 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); 26 } 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; 34 } 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); 39 } 40 if (!ret) { 41 fprintf(stderr, 42 "error: trace event '%s' does not exist\n", line_buf); 43 exit(1); 44 } 45 } 46 } 47 if (fclose(fp) != 0) { 48 fprintf(stderr, "error: closing file '%s': %s\n", 49 fname, strerror(errno)); 50 exit(1); 51 } 52 } 53