]> jfr.im git - irc/quakenet/newserv.git/blobdiff - core/main.c
Add missing #include.
[irc/quakenet/newserv.git] / core / main.c
index 18f2a30a0c7c8b7b1a63b952bae5e739d1389c71..2797e8e2ac56a1066ade13cb6b89566d338642ba 100644 (file)
@@ -1,4 +1,5 @@
 #include "../lib/sstring.h"
+#include "../lib/valgrind.h"
 #include "events.h"
 #include "schedule.h"
 #include "hooks.h"
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 #include <time.h>
 #include <sys/time.h>
 #include <signal.h>
+#include <unistd.h>
 
 void initseed();
 void init_logfile();
+void fini_logfile();
 void siginthandler(int sig);
 void sigusr1handler(int sig);
 void sigsegvhandler(int sig);
@@ -27,6 +31,10 @@ static int newserv_sigint_pending, newserv_sigusr1_pending, newserv_sighup_pendi
 static void (*oldsegv)(int);
 
 int main(int argc, char **argv) {
+  char *config = "newserv.conf";
+
+  nsinit();
+
   initseed();
   inithooks();
   inithandlers();
@@ -37,11 +45,19 @@ int main(int argc, char **argv) {
   initsstring();
   
   if (argc>1) {
-    initconfig(argv[1]);
-  } else {  
-    initconfig("newserv.conf");
+    if (strcmp(argv[1], "--help")==0) {
+      printf("Syntax: %s [config]\n", argv[0]);
+      puts("");
+      printf("Default configuration file unless specified: %s\n", config);
+
+      return 0;
+    }
+
+    config = argv[1];
   }
 
+  initconfig(config);
+
   /* Loading the modules will bring in the bulk of the code */
   initmodules();
   signal(SIGINT, siginthandler);
@@ -62,10 +78,22 @@ int main(int argc, char **argv) {
     handlesignals();
   }  
 
-  nsexit();
-
   freeconfig();
   finisstring();  
+
+  fini_logfile();
+  finischedule();
+  finihandlers();
+
+  nsexit();
+
+  if (RUNNING_ON_VALGRIND) {
+    /* We've already manually called _fini for each of the modules. Make sure
+     * it's not getting called again when the libraries are unloaded. */
+    _exit(0);
+  }
+
+  return 0;
 }
 
 void handlesignals(void) {