Move radius_event_init and modules_init to after the fork
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 17 Nov 2014 06:35:19 +0000 (01:35 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 17 Nov 2014 06:35:37 +0000 (01:35 -0500)
The kqueue used as the main event loop isn't inherited by the child process, and we get weird errors

src/main/radiusd.c

index e9e3ce0..42349c8 100644 (file)
@@ -333,12 +333,6 @@ int main(int argc, char *argv[])
 #endif
 
        /*
-        *  Initialize any event loops just enough so module instantiations can
-        *  add fd/event to them, but do not start them yet.
-        */
-       if (!radius_event_init(autofree)) exit(EXIT_FAILURE);
-
-       /*
         *  Read the configuration files, BEFORE doing anything else.
         */
        if (main_config_init() < 0) exit(EXIT_FAILURE);
@@ -356,11 +350,6 @@ int main(int argc, char *argv[])
 #endif
 
        /*
-        *   Load the modules
-        */
-       if (modules_init(main_config.config) < 0) exit(EXIT_FAILURE);
-
-       /*
         *  Set the panic action (if required)
         */
        if (main_config.panic_action &&
@@ -455,6 +444,20 @@ int main(int argc, char *argv[])
        radius_pid = getpid();
 
        /*
+        *  Initialize any event loops just enough so module instantiations can
+        *  add fd/event to them, but do not start them yet.
+        *
+        *  This has to be done post-fork in case we're using kqueue, where the
+        *  queue isn't inherited by the child process.
+        */
+       if (!radius_event_init(autofree)) exit(EXIT_FAILURE);
+
+       /*
+        *   Load the modules
+        */
+       if (modules_init(main_config.config) < 0) exit(EXIT_FAILURE);
+
+       /*
         *  Redirect stderr/stdout as appropriate.
         */
        if (radlog_init(&default_log, main_config.daemonize) < 0) {