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]>
  • Loading branch information
odivlad committed Sep 10, 2024
1 parent 7ba895f commit de8a402
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/libfrr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,9 +1125,11 @@ 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 +1215,11 @@ 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 de8a402

Please sign in to comment.