]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Attach stdout to child only if --log=stdout and stdout FD is a tty
authorVladislav Odintsov <vlodintsov@k2.cloud>
Wed, 4 Sep 2024 11:18:35 +0000 (14:18 +0300)
committerVladislav Odintsov <vlodintsov@k2.cloud>
Tue, 10 Sep 2024 16:06:13 +0000 (19:06 +0300)
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>
lib/libfrr.c

index 0a575abac6cdcad771e5e4a549f690b619d26095..a1982841d3a7a19fa222a4128711005e1d52de7e 100644 (file)
@@ -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);
        }
 }
@@ -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);
                }