From a47e5f929c244078a87c737ae99294fecfb269c0 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sun, 13 May 2018 00:36:36 +0100 Subject: [PATCH] server/tripe.c: Be more clever about when to switch error output. Organization: Straylight/Edgeware From: Mark Wooding If we're going to detach and be a daemon, then we don't adopt stdin/stdout as an initial administration client -- because we're going to close these streams and disassociate from the surrounding environment. On the other hand, if we /are/ going to adopt stdin/stdout, it makes sense to report errors to the client listening there as soon as we can, so that they can keep informed of our progress. So take advantage of the new flexibility afforded by the `a_switcherr' function, and switch the error output early or late depending on whether we're going to daemonize. --- server/tripe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/tripe.c b/server/tripe.c index 60eaf8f9..60460598 100644 --- a/server/tripe.c +++ b/server/tripe.c @@ -304,6 +304,7 @@ int main(int argc, char *argv[]) if (f & f_foreground) af |= AF_FOREGROUND; a_create(STDIN_FILENO, STDOUT_FILENO, af); + a_switcherr(); } for (i = 0; tunnels[i]; i++) { @@ -316,7 +317,6 @@ int main(int argc, char *argv[]) a_init(); a_signals(); a_listen(csock, u, g, csockmode); - a_switcherr(); u_setugid(u, g); km_init(kr_priv, kr_pub, tag_priv); kx_init(); @@ -324,6 +324,7 @@ int main(int argc, char *argv[]) if (daemonize()) die(EXIT_FAILURE, "couldn't become a daemon: %s", strerror(errno)); a_daemon(); + a_switcherr(); } tv.tv_sec = time(0) + T_INTERVAL; -- [mdw]