Do user switch after SSL keys are initialized
[umurmur.git] / src / main.c
index c1649b6fb20b6ff2e4c24aa8fc431348c2aead51..d98fb6aca3a89b42fa3d4fbe2d21d51cd74208ec 100644 (file)
@@ -55,6 +55,8 @@
 #include "conf.h"
 #include "version.h"
 #include "config.h"
+#include "sharedmemory.h"
+#include "ban.h"
 
 char system_string[64], version_string[64];
 int bindport;
@@ -197,6 +199,10 @@ void daemonize()
        for (i = getdtablesize(); i >= 0; --i)
                close(i); /* close all descriptors */
 
+#ifdef USE_GNUTLS
+        gnutls_global_init();
+#endif
+
        i = open("/dev/null",O_RDWR);
        (void)dup(i);
        (void)dup(i);
@@ -316,13 +322,6 @@ int main(int argc, char **argv)
                        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);
 
@@ -350,13 +349,27 @@ int main(int argc, char **argv)
                Client_init();
                Ban_init();
 
+#ifdef USE_SHAREDMEMORY_API
+    Sharedmemory_init( bindport, bindport6 );
+#endif
+
 #ifdef POSIX_PRIORITY_SCHEDULING
                if (realtime)
                        setscheduler();
 #endif
 
+               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();