From eea86f979ce71f29de0a7b0dd736ce2f15f80eb0 Mon Sep 17 00:00:00 2001 From: kn Date: Tue, 4 Oct 2022 07:03:27 +0000 Subject: [PATCH] Only print prompt in interactive usage Scripting tftp(1) makes it non-interactive, yet the prompt is still printed and may mess up the shell's PS1: $ echo put nonexistent | tftp localhost tftp> tftp: open: nonexistent: No such file or directory tftp> $ The fix seems easy and works as expected for multiple commands as well: $ echo 'verbose\nput nonexistent' | ./obj/tftp localhost Verbose mode on. tftp: open: nonexistent: No such file or directory $ OK millert --- usr.bin/tftp/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c index fe389c3b313..cbfdb07666f 100644 --- a/usr.bin/tftp/main.c +++ b/usr.bin/tftp/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.43 2018/09/20 11:42:42 jsg Exp $ */ +/* $OpenBSD: main.c,v 1.44 2022/10/04 07:03:27 kn Exp $ */ /* $NetBSD: main.c,v 1.6 1995/05/21 16:54:10 mycroft Exp $ */ /* @@ -602,7 +602,8 @@ command(void) struct cmd *c; for (;;) { - printf("%s> ", prompt); + if (isatty(STDIN_FILENO)) + printf("%s> ", prompt); if (readcmd(line, LBUFLEN, stdin) < 1) continue; if ((line[0] == 0) || (line[0] == '\n')) -- 2.20.1