[PATCH 05/23] Insert \n before cmd output when input is not a tty

Valerie Aurora val at versity.com
Fri Apr 4 11:45:21 PDT 2025


From: Auke Kok <auke.kok at versity.com>

The output of piped input commands used by the tests is causing the
output to be concatenated on the line unless the cmd output itself
contains newlines. This is because when input is a pipe, we're not
going to be outputting the cmd's implicit newline. This makes the
output of test scripts a little awkward to read as we're seeing test
output that is relevant pre-pended with several <> line headings. Use
`isatty()` to detect whether stdin is a pipe or not, and insert an
extra newline before outputting cmd output resolves this.

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

diff --git a/cli/debugfs.c b/cli/debugfs.c
index 0b2223a..3b9aab6 100644
--- a/cli/debugfs.c
+++ b/cli/debugfs.c
@@ -216,6 +216,10 @@ static void debugfs_thread(struct thread *thr, void *arg)
 	char **line_argv = NULL;
 	char *line = NULL;
 	int ret;
+	bool is_tty;
+
+	/* if our stdin is not a tty, we want to insert newlines after each cmd */
+	is_tty = isatty(fileno(stdin));
 
 	line = malloc(LINE_SIZE);
 	line_argv = calloc(MAX_ARGC, sizeof(line_argv[0]));
@@ -233,6 +237,9 @@ static void debugfs_thread(struct thread *thr, void *arg)
 		if (!fgets(line, LINE_SIZE, stdin))
 			break;
 
+		if (!is_tty)
+			fprintf(stdout, "\n");
+
 		parse_command(ctx, line, line_argv);
 
 		if (ctx->quit)
-- 
2.48.1




More information about the ngnfs-devel mailing list