Replace ChangeLog appropriately.
[srvx.git] / src / main.c
index bffe2be80d31977222d1fa750b7a8a8e48aa09fa..6966853e801bbdaec6ebbb6a185c804b3ce85480 100644 (file)
@@ -27,6 +27,7 @@
 #include "saxdb.h"
 #include "mail.h"
 #include "timeq.h"
+#include "sar.h"
 
 #include "chanserv.h"
 #include "global.h"
@@ -235,10 +236,10 @@ int main(int argc, char *argv[])
         boot_time = time(&now);
     }
 
-    log_module(MAIN_LOG, LOG_INFO, "Initializing daemon...");
+    fprintf(stdout, "Initializing daemon...\n");
     if (!conf_read(services_config)) {
-       log_module(MAIN_LOG, LOG_FATAL, "Unable to read %s.", services_config);
-       exit(0);
+       fprintf(stderr, "Unable to read %s.\n", services_config);
+       exit(1);
     }
 
     conf_register_reload(uplink_compile);
@@ -247,26 +248,30 @@ int main(int argc, char *argv[])
        /* Attempt to fork into the background if daemon mode is on. */
        pid = fork();
        if (pid < 0) {
-           log_module(MAIN_LOG, LOG_FATAL, "Unable to fork: %s", strerror(errno));
+           fprintf(stderr, "Unable to fork: %s\n", strerror(errno));
         } else if (pid > 0) {
-           log_module(MAIN_LOG, LOG_INFO, "Forking into the background (pid: %i)...", pid);
+           fprintf(stdout, "Forking into the background (pid: %d)...", pid);
            exit(0);
        }
        setsid();
-        /* Close these since we should not use them from now on. */
-        fclose(stdin);
-        fclose(stdout);
-        fclose(stderr);
     }
 
-    if ((file_out = fopen(PID_FILE, "w")) == NULL) {
+    file_out = fopen(PID_FILE, "w");
+    if (file_out == NULL) {
        /* Create the main process' pid file */
-       log_module(MAIN_LOG, LOG_ERROR, "Unable to create PID file: %s", strerror(errno));
+       fprintf(stderr, "Unable to create PID file: %s", strerror(errno));
     } else {
        fprintf(file_out, "%i\n", (int)getpid());
        fclose(file_out);
     }
 
+    if (daemon) {
+        /* Close these since we should not use them from now on. */
+        fclose(stdin);
+        fclose(stdout);
+        fclose(stderr);
+    }
+
     services_argc = argc;
     services_argv = argv;
 
@@ -282,6 +287,7 @@ int main(int argc, char *argv[])
     init_parse();
     modcmd_init();
     saxdb_init();
+    sar_init();
     gline_init();
     mail_init();
     helpfile_init();