[PATCH] Insert \n before cmd output when input is not a tty.
Auke Kok
auke.kok at versity.com
Fri Mar 28 11:20:37 PDT 2025
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 8271148..f2ac71c 100644
--- a/cli/debugfs.c
+++ b/cli/debugfs.c
@@ -807,6 +807,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]));
@@ -824,6 +828,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.47.1
More information about the ngnfs-devel
mailing list