+
+ if (testconfig) {
+ if (!Conf_ok(conffile))
+ exit(1);
+ else
+ exit(0);
+ }
+
+ /* Initialize the config subsystem early;
+ * switch_user() will need to read some config variables as well as logging.
+ */
+ 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);
+#ifdef POSIX_PRIORITY_SCHEDULING
+ /* Set the scheduling policy, has to be called after daemonizing
+ * but before we drop privileges */
+ if (realtime)
+ setscheduler();
+#endif
+
+ }
+ else Log_init(true);
+
+#ifdef POSIX_PRIORITY_SCHEDULING
+ /* We still want to set scheduling policy if nodaemon is specified,
+ * but if we are daemonizing setscheduler() will be called above */
+ if (nodaemon) {
+ if (realtime)
+ setscheduler();
+ }
+#endif
+
+ 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();
+ Ban_init();
+
+#ifdef USE_SHAREDMEMORY_API
+ Sharedmemory_init( bindport, bindport6 );
+#endif
+
+ if(!nodaemon) {
+ /* SSL and scheduling is setup, we can drop privileges now */
+ switch_user();
+
+ /* Reopen log file. If user switch results in access denied, we catch
+ * it early.
+ */
+ Log_reset();
+ }
+
+ Server_run();
+
+#ifdef USE_SHAREDMEMORY_API
+ Sharedmemory_deinit();
+#endif
+
+ Ban_deinit();
+ SSLi_deinit();
+ Chan_free();
+ Log_free();
+ Conf_deinit();
+