chiark / gitweb /
server/tripe.c: Be more clever about when to switch error output.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 12 May 2018 23:36:36 +0000 (00:36 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 25 Jan 2019 12:10:31 +0000 (12:10 +0000)
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

index 60eaf8f9aa7bb8b254eb0a1a204cab5f3ec40d52..60460598a0b85299482322d46356736557b3cf90 100644 (file)
@@ -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;