diff options
author | Renato Westphal <renato@opensourcerouting.org> | 2017-10-03 21:11:07 +0200 |
---|---|---|
committer | Renato Westphal <renato@opensourcerouting.org> | 2017-10-03 22:16:32 +0200 |
commit | 547322cb0f19b37b1a584e9e6ee867e230c648d7 (patch) | |
tree | 03f118b7b8a7dea78b74f025fa1e20b484f9d730 /ldpd | |
parent | ldpd: fix issue when displaying the running configuration (diff) | |
download | frr-547322cb0f19b37b1a584e9e6ee867e230c648d7.tar.xz frr-547322cb0f19b37b1a584e9e6ee867e230c648d7.zip |
ldpd: detach stdin/stdout/stderr from the child processes
Doing a "ssh user@node 'ldpd -d'" was making the SSH session hang. In
the original OpenBSD's ldpd(8) daemon, the daemon function takes care
of connecting stdin/stdout/stderr to /dev/null. In the FRR port, this
only happens in the frr_run() function, after all children have been
forked. Ideally we could try to rearrange libfrr.c and ldpd.c in a way
that start_child() is called only after the parent connects the standard
I/O streams to /dev/null. But since this issue needs an immediate
fix, let's do this workaround for now. Note: even when running on the
foreground, all log messages from the child processes are sent to the
parent process, which then prints the messages to stdout/stderr and/or
to a log file.
Reported-by: Martin Winter <mwinter@opensourcerouting.org>
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'ldpd')
-rw-r--r-- | ldpd/ldpd.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index 95cd4ba36..a79e63229 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -435,7 +435,7 @@ static pid_t start_child(enum ldpd_process p, char *argv0, int fd_async, int fd_sync) { char *argv[3]; - int argc = 0; + int argc = 0, nullfd; pid_t pid; switch (pid = fork()) { @@ -449,6 +449,12 @@ start_child(enum ldpd_process p, char *argv0, int fd_async, int fd_sync) return (pid); } + nullfd = open("/dev/null", O_RDONLY | O_NOCTTY); + dup2(nullfd, 0); + dup2(nullfd, 1); + dup2(nullfd, 2); + close(nullfd); + if (dup2(fd_async, LDPD_FD_ASYNC) == -1) fatal("cannot setup imsg async fd"); if (dup2(fd_sync, LDPD_FD_SYNC) == -1) |