X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/3787a47cc8ce48dc7464c28a7085b62cc795dce0..5f5fc0447463454812f1de465387cf1ca99eaf69:/core/main.c diff --git a/core/main.c b/core/main.c index 7b4c33fb..dfbd7dfe 100644 --- a/core/main.c +++ b/core/main.c @@ -1,4 +1,5 @@ #include "../lib/sstring.h" +#include "../lib/valgrind.h" #include "events.h" #include "schedule.h" #include "hooks.h" @@ -9,9 +10,14 @@ #include #include +#include #include #include +#include +#include +#include #include +#include void initseed(); void init_logfile(); @@ -28,6 +34,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(); @@ -35,12 +45,24 @@ int main(int argc, char **argv) { init_logfile(); - 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); + + /* 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 */ @@ -64,7 +86,6 @@ int main(int argc, char **argv) { } freeconfig(); - finisstring(); fini_logfile(); finischedule(); @@ -72,6 +93,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; }