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.
if (f & f_foreground)
af |= AF_FOREGROUND;
a_create(STDIN_FILENO, STDOUT_FILENO, af);
if (f & f_foreground)
af |= AF_FOREGROUND;
a_create(STDIN_FILENO, STDOUT_FILENO, af);
}
for (i = 0; tunnels[i]; i++) {
}
for (i = 0; tunnels[i]; i++) {
a_init();
a_signals();
a_listen(csock, u, g, csockmode);
a_init();
a_signals();
a_listen(csock, u, g, csockmode);
u_setugid(u, g);
km_init(kr_priv, kr_pub, tag_priv);
kx_init();
u_setugid(u, g);
km_init(kr_priv, kr_pub, tag_priv);
kx_init();
if (daemonize())
die(EXIT_FAILURE, "couldn't become a daemon: %s", strerror(errno));
a_daemon();
if (daemonize())
die(EXIT_FAILURE, "couldn't become a daemon: %s", strerror(errno));
a_daemon();
}
tv.tv_sec = time(0) + T_INTERVAL;
}
tv.tv_sec = time(0) + T_INTERVAL;