+
+ }
+ 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();
+
+ if (pidfile != NULL)
+ unlink(pidfile);
+
+ return 0;
+ }