From e7527ae0eeb3ed45ca3201292c6a19080957876d Mon Sep 17 00:00:00 2001 From: Vladislav Odintsov Date: Wed, 4 Sep 2024 14:18:35 +0300 Subject: [PATCH] lib: Attach stdout to child only if --log=stdout and stdout FD is a tty Prior to this commit stdout of a process started in a daemon mode was attached to a calling process. As a result a calling process hung for infinity. Signed-off-by: Vladislav Odintsov (cherry picked from commit 0e3c5e8e5907321b35201f0985c1d3f4a1b0e639) --- lib/libfrr.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/libfrr.c b/lib/libfrr.c index cb295f7e1b93..d3e20a67531e 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -1110,9 +1110,12 @@ static void frr_terminal_close(int isexit) * don't redirect when stdout is set with --log stdout */ for (fd = 2; fd >= 0; fd--) - if (isatty(fd) && - (fd != STDOUT_FILENO || !logging_to_stdout)) + if (logging_to_stdout && isatty(fd) && + fd == STDOUT_FILENO) { + /* Do nothing. */ + } else { dup2(nullfd, fd); + } close(nullfd); } } @@ -1198,9 +1201,12 @@ void frr_run(struct event_loop *master) * stdout */ for (fd = 2; fd >= 0; fd--) - if (isatty(fd) && - (fd != STDOUT_FILENO || !logging_to_stdout)) + if (logging_to_stdout && isatty(fd) && + fd == STDOUT_FILENO) { + /* Do nothing. */ + } else { dup2(nullfd, fd); + } close(nullfd); }