From fca6ce10dbf01e57ec4777b87faae8b38e53ff43 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 23 Sep 2024 09:13:16 +0100 Subject: [PATCH] Unix Pageant: make stdout line-buffered in --debug mode. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit My normal usage of --debug is to run it in a terminal, where it starts by printing its SSH_AUTH_SOCK setting for me to paste into another terminal to run test commands, and then follows that with diagnostic logging of the requests it's receiving. But if you'd rather get that diagnostic information in some location other than a terminal – say, sent to a file which you're viewing in 'less' so that you can search back and forth in it, or piped to another machine because your test requests are going to come from somewhere out of sight of your monitor – then you might run 'pageant --debug' with its stdout being a pipe or a file rather than a terminal, in which case the standard stdio policy will make it unbuffered, and the diagnostics won't show up in a timely manner. The one-line code change is due to Marco Ricci, who had a rather different motivation. --- unix/pageant.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/unix/pageant.c b/unix/pageant.c index dadbc229..2b72db7c 100644 --- a/unix/pageant.c +++ b/unix/pageant.c @@ -1223,6 +1223,11 @@ void run_agent(FILE *logfp, const char *symlink_path) } else if (life == LIFE_PERM) { pageant_fork_and_print_env(false); } else if (life == LIFE_DEBUG) { + /* Force stdout to be line-buffered in preference to unbuffered, so + * that if diagnostic output is being piped somewhere, it will arrive + * promptly at the other end of the pipe */ + setvbuf(stdout, NULL, _IOLBF, 0); + pageant_print_env(getpid()); upc->logfp = stdout;