- Log_reset();
- }
- else Log_init(true);
-
- signal(SIGCHLD, SIG_IGN); /* ignore child */
- signal(SIGTSTP, SIG_IGN); /* ignore tty signals */
- signal(SIGTTOU, SIG_IGN);
- signal(SIGTTIN, SIG_IGN);
- signal(SIGPIPE, SIG_IGN);
- signal(SIGHUP, signal_handler); /* catch hangup signal */
- signal(SIGTERM, signal_handler); /* catch kill signal */
-
- /* Build system string */
- if (uname(&utsbuf) == 0) {
- snprintf(system_string, 64, "%s %s", utsbuf.sysname, utsbuf.machine);
- snprintf(version_string, 64, "%s", utsbuf.release);
- }
- else {
- snprintf(system_string, 64, "unknown unknown");
- snprintf(version_string, 64, "unknown");
- }
-
- /* Initializing */
- SSLi_init();
- Chan_init();
- Client_init();
+ Conf_init(conffile);
+
+ /* Logging to terminal if not daemonizing, otherwise to syslog or log file.
+ */
+ if (!nodaemon) {
+ daemonize();
+ Log_init(false);
+ if (pidfile != NULL)
+ lockfile(pidfile);
+
+ switch_user();
+
+ /* Reopen log file. If user switch results in access denied, we catch
+ * it early.
+ */
+ Log_reset();
+ }
+ else Log_init(true);
+
+ signal(SIGCHLD, SIG_IGN); /* ignore child */
+ signal(SIGTSTP, SIG_IGN); /* ignore tty signals */
+ signal(SIGTTOU, SIG_IGN);
+ signal(SIGTTIN, SIG_IGN);
+ signal(SIGPIPE, SIG_IGN);
+ signal(SIGHUP, signal_handler); /* catch hangup signal */
+ signal(SIGTERM, signal_handler); /* catch kill signal */
+
+ /* Build system string */
+ if (uname(&utsbuf) == 0) {
+ snprintf(system_string, 64, "%s %s", utsbuf.sysname, utsbuf.machine);
+ snprintf(version_string, 64, "%s", utsbuf.release);
+ }
+ else {
+ snprintf(system_string, 64, "unknown unknown");
+ snprintf(version_string, 64, "unknown");
+ }