trace-cmd record/set: Use write() instead of fwrite() for options
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.
Link: https://lore.kernel.org/20250826105223.4b857921@gandalf.local.home
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 47486e9..4e1157c 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -1964,22 +1964,23 @@
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)