Skip to content

Commit

Permalink
Merge pull request #16738 from odivlad/fix-stdout-fork
Browse files Browse the repository at this point in the history
lib: Attach stdout to child only if --log=stdout and stdout FD is a tty
  • Loading branch information
ton31337 authored Sep 19, 2024
2 parents b5e266b + 0e3c5e8 commit 74f1285
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 @@ -1125,9 +1125,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 @@ -1213,9 +1216,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 74f1285

Please sign in to comment.