[PATCH] Insert \n before cmd output when input is not a tty.
Valerie Aurora
val at versity.com
Wed Apr 2 10:55:27 PDT 2025
On Fri, Mar 28, 2025 at 7:20 PM Auke Kok <auke.kok at versity.com> wrote:
>
> 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
Thanks for this, this problem has been annoying me. I put it in my
tree where it has already helped me debug something.
Valerie
More information about the ngnfs-devel
mailing list