diff mbox series

[11/11] libtracefs/Documentation: Update stream example to have a parameter

Message ID 20211122234956.788401-12-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit 80f8654692643cfb05ecc3569c7f71ec6e6d23aa
Headers show
Series libtracefs: Have all man page examples be executable | expand

Commit Message

Steven Rostedt Nov. 22, 2021, 11:49 p.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Instead of writing the output of the tracing data to trace.txt, have the
example require a file name. As it is now compiled out, it should not
create some random file that the user will not expect.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/libtracefs-stream.txt | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/Documentation/libtracefs-stream.txt b/Documentation/libtracefs-stream.txt
index 48fc8fa..7d723c5 100644
--- a/Documentation/libtracefs-stream.txt
+++ b/Documentation/libtracefs-stream.txt
@@ -47,6 +47,8 @@  EXAMPLE
 -------
 [source,c]
 --
+#include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <signal.h>
 
@@ -57,13 +59,23 @@  void stop(int sig)
 	tracefs_trace_pipe_stop(NULL);
 }
 
-int main()
+int main(int argc, char **argv)
 {
 	mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
-	const char *filename = "trace.txt";
-	int fd = creat(filename, mode);
+	const char *filename;
+	int fd;
 	int ret;
 
+	if (argc < 2) {
+		fprintf(stderr, "usage: %s output_file\n", argv[0]);
+		exit(-1);
+	}
+	filename = argv[1];
+	fd = creat(filename, mode);
+	if (fd < 0) {
+		perror(filename);
+		exit(-1);
+	}
 	signal(SIGINT, stop);
 	ret = tracefs_trace_pipe_stream(fd, NULL, SPLICE_F_NONBLOCK);
 	close(fd);