Skip to content

Commit

Permalink
lib: Attach stdout to child only if --log=stdout and stdout FD is a tty
Browse files Browse the repository at this point in the history
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 <[email protected]>
(cherry picked from commit 0e3c5e8)
  • Loading branch information
odivlad authored and mergify[bot] committed Oct 1, 2024
1 parent cd82888 commit b496e4b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/libfrr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit b496e4b

Please sign in to comment.