From: Mark Wooding Date: Sat, 12 May 2018 23:36:36 +0000 (+0100) Subject: server/tripe.c: Be more clever about when to switch error output. X-Git-Tag: 1.5.0~31 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/commitdiff_plain/a47e5f929c244078a87c737ae99294fecfb269c0?ds=sidebyside server/tripe.c: Be more clever about when to switch error output. 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. --- 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;