diff options
| author | Vladislav Odintsov <vlodintsov@k2.cloud> | 2024-09-04 14:18:35 +0300 |
|---|---|---|
| committer | Mergify <37929162+mergify[bot]@users.noreply.github.com> | 2024-10-01 07:49:43 +0000 |
| commit | b496e4b1dff738f1bcff25d13e7575b2f835033b (patch) | |
| tree | 37eacfbb1ac3fefe085dc2a0e5b14017e1f4edd5 /lib | |
| parent | cd82888fe82c54c2596dc8dd1495fc5c21c86631 (diff) | |
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 <vlodintsov@k2.cloud>
(cherry picked from commit 0e3c5e8e5907321b35201f0985c1d3f4a1b0e639)
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/libfrr.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/libfrr.c b/lib/libfrr.c index 33237df5fc..3187d8d4b6 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -1108,9 +1108,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); } } @@ -1196,9 +1199,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); } |
