diff options
| author | Steven Rostedt <srostedt@redhat.com> | 2010-01-18 13:14:25 -0500 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2010-01-18 13:14:25 -0500 |
| commit | 7ad960c1cc3ca0e73abc1ecfc97c46f46ba04197 (patch) | |
| tree | 204e1d86c1dce506667213fccc410ad8de3cdab9 | |
| parent | 8863e82fd8276a8150df7faf16f8ce7d327f0c3f (diff) | |
trace-cmd: Cache tracing_on file descriptor
Cache the tracing_on file descriptor to have the disable_tracing()
be able to shut down tracing without having to reopen the
tracing_on file.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| -rw-r--r-- | trace-cmd.c | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/trace-cmd.c b/trace-cmd.c index 8839e74..a073017 100644 --- a/trace-cmd.c +++ b/trace-cmd.c | |||
| @@ -459,34 +459,37 @@ static void disable_event(const char *name) | |||
| 459 | fclose(fp); | 459 | fclose(fp); |
| 460 | } | 460 | } |
| 461 | 461 | ||
| 462 | static void enable_tracing(void) | 462 | static void write_tracing_on(int on) |
| 463 | { | 463 | { |
| 464 | FILE *fp; | 464 | static int fd = -1; |
| 465 | char *path; | 465 | char *path; |
| 466 | int ret; | ||
| 466 | 467 | ||
| 467 | /* reset the trace */ | 468 | if (fd < 0) { |
| 468 | path = get_tracing_file("tracing_on"); | 469 | path = get_tracing_file("tracing_on"); |
| 469 | fp = fopen(path, "w"); | 470 | fd = open(path, O_WRONLY); |
| 470 | if (!fp) | 471 | if (fd < 0) |
| 471 | die("writing to '%s'", path); | 472 | die("opening '%s'", path); |
| 472 | put_tracing_file(path); | 473 | put_tracing_file(path); |
| 473 | fwrite("1", 1, 1, fp); | 474 | } |
| 474 | fclose(fp); | 475 | |
| 476 | if (on) | ||
| 477 | ret = write(fd, "1", 1); | ||
| 478 | else | ||
| 479 | ret = write(fd, "0", 1); | ||
| 480 | |||
| 481 | if (ret < 0) | ||
| 482 | die("writing 'tracing_on'"); | ||
| 475 | } | 483 | } |
| 476 | 484 | ||
| 477 | static void disable_tracing(void) | 485 | static void enable_tracing(void) |
| 478 | { | 486 | { |
| 479 | FILE *fp; | 487 | write_tracing_on(1); |
| 480 | char *path; | 488 | } |
| 481 | 489 | ||
| 482 | /* reset the trace */ | 490 | static void disable_tracing(void) |
| 483 | path = get_tracing_file("tracing_on"); | 491 | { |
| 484 | fp = fopen(path, "w"); | 492 | write_tracing_on(0); |
| 485 | if (!fp) | ||
| 486 | die("writing to '%s'", path); | ||
| 487 | put_tracing_file(path); | ||
| 488 | fwrite("0", 1, 1, fp); | ||
| 489 | fclose(fp); | ||
| 490 | } | 493 | } |
| 491 | 494 | ||
| 492 | static void disable_all(void) | 495 | static void disable_all(void) |
