From 22acc84215d3e70d0ce4c9989f3d3c4449babddf Mon Sep 17 00:00:00 2001 From: frostycoolslug Date: Sat, 27 Sep 2003 04:02:46 +0000 Subject: Fixed Bug Causing missing modules to Seg Fault The IRCd, now the missing modules are ignored. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@188 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/inspircd.cpp | 47 +++++++++++++++++++++++++++++++---------------- src/inspircd_io.cpp | 10 +++++++++- 2 files changed, 40 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 3674c55a7..065e94524 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -4067,32 +4067,47 @@ int InspIRCd(void) log(DEBUG,"InspIRCd: startup: InspIRCd is now running!"); printf("\n"); - for (count = 0; count < ConfValueEnum("module"); count++) + + /* BugFix By Craig! :p */ + count2 = 0; + for (count = 0; count2 < ConfValueEnum("module"); count2++) { char modfile[MAXBUF]; ConfValue("module","name",count,configToken); sprintf(modfile,"%s/%s",MOD_PATH,configToken); printf("Loading module... \033[1;37m%s\033[0;37m\n",modfile); log(DEBUG,"InspIRCd: startup: Loading module: %s",modfile); - - factory[count] = new ircd_module(modfile); - if (factory[count]->LastError()) + /* If The File Doesnt exist, Trying to load it + * Will Segfault the IRCd.. So, check to see if + * it Exists, Before Proceeding. */ + if (CheckModule(modfile)) { - log(DEBUG,"Unable to load %s: %s",modfile,factory[count]->LastError()); - sprintf("Unable to load %s: %s\nExiting...\n",modfile,factory[count]->LastError()); - Exit(ERROR); - } - if (factory[count]->factory) - { - modules[count] = factory[count]->factory->CreateModule(); - /* save the module and the module's classfactory, if - * this isnt done, random crashes can occur :/ */ + factory[count] = new ircd_module(modfile); + if (factory[count]->LastError()) + { + log(DEBUG,"Unable to load %s: %s",modfile,factory[count]->LastError()); + sprintf("Unable to load %s: %s\nExiting...\n",modfile,factory[count]->LastError()); + Exit(ERROR); + } + if (factory[count]->factory) + { + modules[count] = factory[count]->factory->CreateModule(); + /* save the module and the module's classfactory, if + * this isnt done, random crashes can occur :/ */ + } + else + { + log(DEBUG,"Unable to load %s",modfile); + sprintf("Unable to load %s\nExiting...\n",modfile); + Exit(ERROR); + } + /* Increase the Count */ + count++; } else { - log(DEBUG,"Unable to load %s",modfile); - sprintf("Unable to load %s\nExiting...\n",modfile); - Exit(ERROR); + log(DEBUG,"InspIRCd: startup: Module Not Found %s",modfile); + printf("Module Not Found: \033[1;37m%s\033[0;37m, Skipping\n",modfile); } } MODCOUNT = count - 1; diff --git a/src/inspircd_io.cpp b/src/inspircd_io.cpp index 366fa799c..f1e7bf66c 100644 --- a/src/inspircd_io.cpp +++ b/src/inspircd_io.cpp @@ -85,7 +85,15 @@ int DaemonSeed (void) } - +/* Make Sure Modules Are Avaliable! + * (BugFix By Craig.. See? I do work! :p) */ +int CheckModule (char module[MAXBUF]) +{ + FILE *input; + + if ((input = fopen (module, "r")) == NULL) { return(FALSE); } + else { fclose (input); return(TRUE); } +} /* Make sure the config file is available */ int CheckConfig (void) -- cgit v1.2.3