[PATCH] Echo command with newline back to pipe output.

Auke Kok auke.kok at versity.com
Tue Apr 8 14:11:44 PDT 2025


To facilitate readability of the output files, we echo the full command,
including the terminating newline, back to the output if it's not a tty.

Signed-off-by: Auke Kok <auke.kok at versity.com>
---
 cli/debugfs.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/cli/debugfs.c b/cli/debugfs.c
index 542adaf..e2889d2 100644
--- a/cli/debugfs.c
+++ b/cli/debugfs.c
@@ -791,6 +791,7 @@ static void debugfs_thread(struct thread *thr, void *arg)
 	char **line_argv = NULL;
 	char *line = NULL;
 	int ret;
+	bool is_tty = isatty(STDIN_FILENO);
 
 	line = malloc(LINE_SIZE);
 	line_argv = calloc(MAX_ARGC, sizeof(line_argv[0]));
@@ -808,6 +809,14 @@ static void debugfs_thread(struct thread *thr, void *arg)
 		if (!fgets(line, LINE_SIZE, stdin))
 			break;
 
+		/*
+		 * Copy the entire line (with \n at the end) back to the output if
+		 * we're reading from a pipe. This makes the output readable like a
+		 * full log of what commands were performed.
+		 */
+		if (!is_tty)
+			fprintf(stdout, "%s", line);
+
 		parse_command(ctx, line, line_argv);
 
 		if (ctx->quit)
-- 
2.49.0




More information about the ngnfs-devel mailing list