diff options
author | Steven Rostedt (VMware) <rostedt@goodmis.org> | 2019-03-12 21:13:19 -0400 |
---|---|---|
committer | Steven Rostedt (VMware) <rostedt@goodmis.org> | 2019-03-12 21:13:19 -0400 |
commit | cbd567febd2559b055576ec48312fa53f46f76f5 (patch) | |
tree | c2eb0eeec3ddc616a597e160f1e82e6115a74876 | |
parent | 5809bf1e0bb9c058c6517043ff87b125530e9ed0 (diff) | |
download | trace-cmd-cbd567febd2559b055576ec48312fa53f46f76f5.tar.gz |
trace-cmd: Move write_instance_file() up in file
To allow for reset_max_latency() and add_filter_pid() to utilize
write_instance_file(), move it up before those functions. It is in a better
location now as well.
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r-- | tracecmd/trace-record.c | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 00dc5ad7..f1f5d29d 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -776,6 +776,45 @@ get_instance_dir(struct buffer_instance *instance) return path; } +static int write_file(const char *file, const char *str, const char *type) +{ + char buf[BUFSIZ]; + int fd; + int ret; + + fd = open(file, O_WRONLY | O_TRUNC); + if (fd < 0) + die("opening to '%s'", file); + ret = write(fd, str, strlen(str)); + close(fd); + if (ret < 0 && type) { + /* write failed */ + fd = open(file, O_RDONLY); + if (fd < 0) + die("writing to '%s'", file); + /* the filter has the error */ + while ((ret = read(fd, buf, BUFSIZ)) > 0) + fprintf(stderr, "%.*s", ret, buf); + die("Failed %s of %s\n", type, file); + close(fd); + } + return ret; +} + +static int +write_instance_file(struct buffer_instance *instance, + const char *file, const char *str, const char *type) +{ + char *path; + int ret; + + path = get_instance_file(instance, file); + ret = write_file(path, str, type); + tracecmd_put_tracing_file(path); + + return ret; +} + static void __clear_trace(struct buffer_instance *instance) { FILE *fp; @@ -1596,45 +1635,6 @@ static void reset_events(void) reset_events_instance(instance); } -static int write_file(const char *file, const char *str, const char *type) -{ - char buf[BUFSIZ]; - int fd; - int ret; - - fd = open(file, O_WRONLY | O_TRUNC); - if (fd < 0) - die("opening to '%s'", file); - ret = write(fd, str, strlen(str)); - close(fd); - if (ret < 0 && type) { - /* write failed */ - fd = open(file, O_RDONLY); - if (fd < 0) - die("writing to '%s'", file); - /* the filter has the error */ - while ((ret = read(fd, buf, BUFSIZ)) > 0) - fprintf(stderr, "%.*s", ret, buf); - die("Failed %s of %s\n", type, file); - close(fd); - } - return ret; -} - -static int -write_instance_file(struct buffer_instance *instance, - const char *file, const char *str, const char *type) -{ - char *path; - int ret; - - path = get_instance_file(instance, file); - ret = write_file(path, str, type); - tracecmd_put_tracing_file(path); - - return ret; -} - enum { STATE_NEWLINE, STATE_SKIP, |