2
0

control.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include "trace/control.h"
  10. void trace_backend_init_events(const char *fname)
  11. {
  12. if (fname == NULL) {
  13. return;
  14. }
  15. FILE *fp = fopen(fname, "r");
  16. if (!fp) {
  17. fprintf(stderr, "error: could not open trace events file '%s': %s\n",
  18. fname, strerror(errno));
  19. exit(1);
  20. }
  21. char line_buf[1024];
  22. while (fgets(line_buf, sizeof(line_buf), fp)) {
  23. size_t len = strlen(line_buf);
  24. if (len > 1) { /* skip empty lines */
  25. line_buf[len - 1] = '\0';
  26. if (!trace_event_set_state(line_buf, true)) {
  27. fprintf(stderr,
  28. "error: trace event '%s' does not exist\n", line_buf);
  29. exit(1);
  30. }
  31. }
  32. }
  33. if (fclose(fp) != 0) {
  34. fprintf(stderr, "error: closing file '%s': %s\n",
  35. fname, strerror(errno));
  36. exit(1);
  37. }
  38. }