From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx> In order to try multiple methods of writing to the filter file, the opening of the filter file needs to be in the tracefs_function_filter() call, and allow that to be passed to multiple ways of writing to the filter. Link: https://lore.kernel.org/linux-trace-devel/20210323013224.877520803@xxxxxxxxxxx Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx> --- src/tracefs-tools.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/tracefs-tools.c b/src/tracefs-tools.c index 4f8bcdc299df..02e43168a810 100644 --- a/src/tracefs-tools.c +++ b/src/tracefs-tools.c @@ -389,24 +389,18 @@ void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt options->mask &= ~(1ULL << (id - 1)); } -static int controlled_write(const char *filter_path, const char **filters, - const char *module, bool reset, const char ***errs) +static int controlled_write(int fd, const char **filters, + const char *module, const char ***errs) { - int flags = reset ? O_TRUNC : O_APPEND; const char **temp = NULL; const char **e = NULL; char *each_str = NULL; int write_size = 0; int size = 0; - int fd = -1; int ret = 0; int j = 0; int i; - fd = open(filter_path, O_WRONLY | flags); - if (fd < 0) - return 1; - for (i = 0; filters[i]; i++) { if (module) write_size = asprintf(&each_str, "%s:mod:%s ", filters[i], module); @@ -449,7 +443,6 @@ static int controlled_write(const char *filter_path, const char **filters, error: if (each_str) free(each_str); - close(fd); return ret; } @@ -486,6 +479,8 @@ int tracefs_function_filter(struct tracefs_instance *instance, const char **filt { char *ftrace_filter_path; int ret = 0; + int flags; + int fd; if (!filters) return 1; @@ -494,7 +489,16 @@ int tracefs_function_filter(struct tracefs_instance *instance, const char **filt if (!ftrace_filter_path) return 1; - ret = controlled_write(ftrace_filter_path, filters, module, reset, errs); + flags = reset ? O_TRUNC : O_APPEND; + + fd = open(ftrace_filter_path, O_WRONLY | flags); tracefs_put_tracing_file(ftrace_filter_path); + if (fd < 0) + return 1; + + ret = controlled_write(fd, filters, module, errs); + + close(fd); + return ret; } -- 2.30.1