[PATCH] trace-cmd record/set: Use write() instead of fwrite() for options
Steven Rostedt <[email protected]> Tue, 26 Aug 2025 10:52:23 -0400
| Newsgroups | org.kernel.vger.linux-trace-devel |
|---|---|
| Message-ID | <[email protected]> |
From: "Steven Rostedt (Google)" <[email protected]> For some reason, using fwrite() to write to trace_options does not return the error messages. When using -O userstacktrace_delay on a system that did not have it supported, the fwrite() succeeds and the user of trace-cmd things the option is set. This is confusing when looking at the output and not seeing the delayed stack traces. Switch fopen()/fwrite() over to open()/write() where there's no dependency on glibc getting it correct. Signed-off-by: Steven Rostedt (Google) <[email protected]> --- tracecmd/trace-record.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index f36ee6cd..4872d0d7 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -1964,22 +1964,23 @@ static void save_option(struct buffer_instance *instance, const char *option) static int set_option(struct buffer_instance *instance, const char *option) { - FILE *fp; char *path; + int ret; + int fd; path = tracefs_instance_get_file(instance->tracefs, "trace_options"); - fp = fopen(path, "w"); - if (!fp) + fd = open(path, O_WRONLY | O_TRUNC); + if (fd < 0) warning("writing to '%s'", path); tracefs_put_tracing_file(path); - if (!fp) + if (fd < 0) return -1; - fwrite(option, 1, strlen(option), fp); - fclose(fp); + ret = write(fd, option, strlen(option)); + close(fd); - return 0; + return ret < 0 ? ret : 0; } static void disable_func_stack_trace_instance(struct buffer_instance *instance) -- 2.47.2