]> jfr.im git - irc/quakenet/newserv.git/blobdiff - core/main.c
CHANSERV: remove E type escapes
[irc/quakenet/newserv.git] / core / main.c
index 3f4ad31064f37ec6f5138b6bf7956f921c6e9520..a9adc188bc0dad1cb0ccd34ed7d23a2b3c81b0e2 100644 (file)
@@ -1,4 +1,5 @@
 #include "../lib/sstring.h"
+#include "../lib/valgrind.h"
 #include "events.h"
 #include "schedule.h"
 #include "hooks.h"
 #include <string.h>
 #include <time.h>
 #include <sys/time.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <errno.h>
 #include <signal.h>
+#include <unistd.h>
 
 void initseed();
 void init_logfile();
@@ -31,6 +36,8 @@ static void (*oldsegv)(int);
 int main(int argc, char **argv) {
   char *config = "newserv.conf";
 
+  nsinit();
+
   initseed();
   inithooks();
   inithandlers();
@@ -38,8 +45,6 @@ int main(int argc, char **argv) {
 
   init_logfile();
   
-  initsstring();
-  
   if (argc>1) {
     if (strcmp(argv[1], "--help")==0) {
       printf("Syntax: %s [config]\n", argv[0]);
@@ -54,8 +59,15 @@ int main(int argc, char **argv) {
 
   initconfig(config);
 
+  /* modules can rely on this directory always being there */
+  if (mkdir("data", 0700) < 0 && errno != EEXIST) {
+    perror("mkdir");
+    return 1;
+  }
+
   /* Loading the modules will bring in the bulk of the code */
   initmodules();
+  signal(SIGPIPE, SIG_IGN);
   signal(SIGINT, siginthandler);
   signal(SIGUSR1, sigusr1handler);
   signal(SIGHUP, sighuphandler);
@@ -75,7 +87,6 @@ int main(int argc, char **argv) {
   }  
 
   freeconfig();
-  finisstring();  
 
   fini_logfile();
   finischedule();
@@ -83,6 +94,12 @@ int main(int argc, char **argv) {
 
   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;
 }