From cd5a23168280917774094eeb77b5a359e4f4a292 Mon Sep 17 00:00:00 2001 From: Tzvetomir Stoyanov Date: Mon, 11 Mar 2019 10:33:37 +0200 Subject: [PATCH 2/4] trace-cmd: Refactore add_event_pid()to utilize write_instance_file() This patch changes add_event_pid() to utilize write_instance_file() for writing set_event_pid instance file, instead of directly opening it. Link: http://lore.kernel.org/linux-trace-devel/20190311083339.21581-5-tstoyanov@vmware.com Reviewed-by: Slavomir Kaslev Signed-off-by: Tzvetomir Stoyanov Signed-off-by: Steven Rostedt (VMware) --- tracecmd/trace-record.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index f1f5d29d..801dad24 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -1133,30 +1133,25 @@ static void update_sched_events(struct buffer_instance *instance, int pid) static int open_instance_fd(struct buffer_instance *instance, const char *file, int flags); -static void add_event_pid(const char *buf, int len) +static void add_event_pid(const char *buf) { struct buffer_instance *instance; - int fd; - for_all_instances(instance) { - fd = open_instance_fd(instance, "set_event_pid", O_WRONLY); - write(fd, buf, len); - close(fd); - } + for_all_instances(instance) + write_instance_file(instance, "set_event_pid", buf, "event_pid"); } static void add_new_filter_pid(int pid) { struct buffer_instance *instance; char buf[100]; - int len; add_filter_pid(pid, 0); - len = sprintf(buf, "%d", pid); + sprintf(buf, "%d", pid); update_ftrace_pid(buf, 0); if (have_set_event_pid) - return add_event_pid(buf, len); + return add_event_pid(buf); common_pid_filter = append_pid_filter(common_pid_filter, "common_pid", pid); -- 2.20.1