Skip to content

Commit 0e3c5e8

Browse files
committed
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 <[email protected]>
1 parent 2b4a262 commit 0e3c5e8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/libfrr.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -1125,9 +1125,12 @@ static void frr_terminal_close(int isexit)
11251125
* don't redirect when stdout is set with --log stdout
11261126
*/
11271127
for (fd = 2; fd >= 0; fd--)
1128-
if (isatty(fd) &&
1129-
(fd != STDOUT_FILENO || !logging_to_stdout))
1128+
if (logging_to_stdout && isatty(fd) &&
1129+
fd == STDOUT_FILENO) {
1130+
/* Do nothing. */
1131+
} else {
11301132
dup2(nullfd, fd);
1133+
}
11311134
close(nullfd);
11321135
}
11331136
}
@@ -1213,9 +1216,12 @@ void frr_run(struct event_loop *master)
12131216
* stdout
12141217
*/
12151218
for (fd = 2; fd >= 0; fd--)
1216-
if (isatty(fd) &&
1217-
(fd != STDOUT_FILENO || !logging_to_stdout))
1219+
if (logging_to_stdout && isatty(fd) &&
1220+
fd == STDOUT_FILENO) {
1221+
/* Do nothing. */
1222+
} else {
12181223
dup2(nullfd, fd);
1224+
}
12191225
close(nullfd);
12201226
}
12211227

0 commit comments

Comments
 (0)