Fix bug in m_dnsbl, a condition is always matched because someone was using unsigned int to check a return val that can be -1 *slap w00t*

Change around the way exit codes are formed so that we can return a sensible exit code that reflects why inspircd exited


git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6076 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
brain 2006-12-23 16:40:09 +00:00
parent e04f190f63
commit de3978c580
7 changed files with 27 additions and 21 deletions

View File

@ -14,6 +14,7 @@
#include "configreader.h" #include "configreader.h"
#include "users.h" #include "users.h"
#include "commands/cmd_die.h" #include "commands/cmd_die.h"
#include "exitcodes.h"
extern "C" command_t* init_command(InspIRCd* Instance) extern "C" command_t* init_command(InspIRCd* Instance)
{ {
@ -44,7 +45,7 @@ CmdResult cmd_die::Handle (const char** parameters, int pcnt, userrec *user)
} }
sleep(ServerInstance->Config->DieDelay); sleep(ServerInstance->Config->DieDelay);
InspIRCd::Exit(ERROR); InspIRCd::Exit(EXIT_STATUS_DIE);
} }
else else
{ {

View File

@ -16,6 +16,7 @@
#include <fstream> #include <fstream>
#include "inspircd.h" #include "inspircd.h"
#include "xline.h" #include "xline.h"
#include "exitcodes.h"
std::vector<std::string> old_module_names, new_module_names, added_modules, removed_modules; std::vector<std::string> old_module_names, new_module_names, added_modules, removed_modules;
@ -152,7 +153,7 @@ bool ServerConfig::CheckOnce(char* tag, bool bail, userrec* user)
if (bail) if (bail)
{ {
printf("There were errors in your configuration:\nYou have more than one <%s> tag, this is not permitted.\n",tag); printf("There were errors in your configuration:\nYou have more than one <%s> tag, this is not permitted.\n",tag);
InspIRCd::Exit(ERROR); InspIRCd::Exit(EXIT_STATUS_CONFIG);
} }
else else
{ {
@ -174,7 +175,7 @@ bool ServerConfig::CheckOnce(char* tag, bool bail, userrec* user)
if (bail) if (bail)
{ {
printf("There were errors in your configuration:\nYou have not defined a <%s> tag, this is required.\n",tag); printf("There were errors in your configuration:\nYou have not defined a <%s> tag, this is required.\n",tag);
InspIRCd::Exit(ERROR); InspIRCd::Exit(EXIT_STATUS_CONFIG);
} }
else else
{ {
@ -552,7 +553,7 @@ void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail,
{ {
/* Unneeded because of the ServerInstance->Log() aboive? */ /* Unneeded because of the ServerInstance->Log() aboive? */
printf("There were errors in your configuration:\n%s\n\n",errormessage.c_str()); printf("There were errors in your configuration:\n%s\n\n",errormessage.c_str());
InspIRCd::Exit(ERROR); InspIRCd::Exit(EXIT_STATUS_CONFIG);
} }
else else
{ {

View File

@ -19,6 +19,7 @@
#include "mode.h" #include "mode.h"
#include "xline.h" #include "xline.h"
#include "inspircd.h" #include "inspircd.h"
#include "exitcodes.h"
static char TIMESTR[26]; static char TIMESTR[26];
static time_t LAST = 0; static time_t LAST = 0;
@ -448,7 +449,7 @@ void InspIRCd::OpenLog(char** argv, int argc)
if (!Config->log_file) if (!Config->log_file)
{ {
printf("ERROR: Could not write to logfile %s: %s\n\n", Config->logpath.c_str(), strerror(errno)); printf("ERROR: Could not write to logfile %s: %s\n\n", Config->logpath.c_str(), strerror(errno));
Exit(ERROR); Exit(EXIT_STATUS_LOG);
} }
this->Logger = new FileLogger(this, Config->log_file); this->Logger = new FileLogger(this, Config->log_file);
@ -460,7 +461,7 @@ void InspIRCd::CheckRoot()
{ {
printf("WARNING!!! You are running an irc server as ROOT!!! DO NOT DO THIS!!!\n\n"); printf("WARNING!!! You are running an irc server as ROOT!!! DO NOT DO THIS!!!\n\n");
this->Log(DEFAULT,"Cant start as root"); this->Log(DEFAULT,"Cant start as root");
Exit(ERROR); Exit(EXIT_STATUS_ROOT);
} }
} }
@ -470,7 +471,7 @@ void InspIRCd::CheckDie()
{ {
printf("WARNING: %s\n\n",Config->DieValue); printf("WARNING: %s\n\n",Config->DieValue);
this->Log(DEFAULT,"Died because of <die> tag: %s",Config->DieValue); this->Log(DEFAULT,"Died because of <die> tag: %s",Config->DieValue);
Exit(ERROR); Exit(EXIT_STATUS_DIETAG);
} }
} }
@ -490,7 +491,7 @@ void InspIRCd::LoadAllModules()
{ {
this->Log(DEFAULT,"There was an error loading a module: %s", this->ModuleError()); this->Log(DEFAULT,"There was an error loading a module: %s", this->ModuleError());
printf("\nThere was an error loading a module: %s\n\n",this->ModuleError()); printf("\nThere was an error loading a module: %s\n\n",this->ModuleError());
Exit(ERROR); Exit(EXIT_STATUS_MODULE);
} }
} }
printf("\nA total of \033[1;32m%d\033[0m module%s been loaded.\n", this->ModCount+1, this->ModCount+1 == 1 ? " has" : "s have"); printf("\nA total of \033[1;32m%d\033[0m module%s been loaded.\n", this->ModCount+1, this->ModCount+1 == 1 ? " has" : "s have");

View File

@ -25,6 +25,7 @@
#include "socket.h" #include "socket.h"
#include "typedefs.h" #include "typedefs.h"
#include "command_parse.h" #include "command_parse.h"
#include "exitcodes.h"
#include <dlfcn.h> #include <dlfcn.h>
using irc::sockets::NonBlocking; using irc::sockets::NonBlocking;
@ -65,10 +66,9 @@ void InspIRCd::Exit(int status)
{ {
if (SI) if (SI)
{ {
SI->SendError("Exiting with status " + ConvToStr(status)); SI->SendError("Exiting with status " + ConvToStr(status) + " (" + std::string(ExitCodes[status]) + ")");
SI->Cleanup(); SI->Cleanup();
} }
exit (status); exit (status);
} }
@ -167,7 +167,7 @@ bool InspIRCd::DaemonSeed()
*/ */
while (kill(childpid, 0) != -1) while (kill(childpid, 0) != -1)
sleep(1); sleep(1);
exit(ERROR); Exit(EXIT_STATUS_FORK);
} }
setsid (); setsid ();
umask (007); umask (007);
@ -212,7 +212,7 @@ void InspIRCd::WritePID(const std::string &filename)
{ {
printf("Failed to write PID-file '%s', exiting.\n",fname.c_str()); printf("Failed to write PID-file '%s', exiting.\n",fname.c_str());
this->Log(DEFAULT,"Failed to write PID-file '%s', exiting.",fname.c_str()); this->Log(DEFAULT,"Failed to write PID-file '%s', exiting.",fname.c_str());
Exit(0); Exit(EXIT_STATUS_PID);
} }
} }
@ -245,7 +245,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
printf("ERROR: Cannot open config file: %s\nExiting...\n",CONFIG_FILE); printf("ERROR: Cannot open config file: %s\nExiting...\n",CONFIG_FILE);
this->Log(DEFAULT,"main: no config"); this->Log(DEFAULT,"main: no config");
printf("ERROR: Your config file is missing, this IRCd will self destruct in 10 seconds!\n"); printf("ERROR: Your config file is missing, this IRCd will self destruct in 10 seconds!\n");
Exit(ERROR); Exit(EXIT_STATUS_CONFIG);
} }
*this->LogFileName = 0; *this->LogFileName = 0;
if (argc > 1) { if (argc > 1) {
@ -277,14 +277,14 @@ InspIRCd::InspIRCd(int argc, char** argv)
else else
{ {
printf("ERROR: The -logfile parameter must be followed by a log file name and path.\n"); printf("ERROR: The -logfile parameter must be followed by a log file name and path.\n");
Exit(ERROR); Exit(EXIT_STATUS_CONFIG);
} }
i++; i++;
} }
else else
{ {
printf("Usage: %s [-nofork] [-nolog] [-debug] [-wait] [-logfile <filename>]\n",argv[0]); printf("Usage: %s [-nofork] [-nolog] [-debug] [-wait] [-logfile <filename>]\n",argv[0]);
Exit(ERROR); Exit(EXIT_STATUS_ARGV);
} }
} }
} }
@ -317,7 +317,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
if (!this->DaemonSeed()) if (!this->DaemonSeed())
{ {
printf("ERROR: could not go into daemon mode. Shutting down.\n"); printf("ERROR: could not go into daemon mode. Shutting down.\n");
Exit(ERROR); Exit(EXIT_STATUS_FORK);
} }
} }
@ -337,7 +337,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
if ((stats->BoundPortCount == 0) && (found_ports > 0)) if ((stats->BoundPortCount == 0) && (found_ports > 0))
{ {
printf("\nERROR: I couldn't bind any ports! Are you sure you didn't start InspIRCd twice?\n"); printf("\nERROR: I couldn't bind any ports! Are you sure you didn't start InspIRCd twice?\n");
Exit(ERROR); Exit(EXIT_STATUS_BIND);
} }
if (stats->BoundPortCount != (unsigned int)found_ports) if (stats->BoundPortCount != (unsigned int)found_ports)
@ -361,7 +361,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
if (!SE->AddFd(Config->openSockfd[count])) if (!SE->AddFd(Config->openSockfd[count]))
{ {
printf("\nEH? Could not add listener to socketengine. You screwed up, aborting.\n"); printf("\nEH? Could not add listener to socketengine. You screwed up, aborting.\n");
Exit(ERROR); Exit(EXIT_STATUS_INTERNAL);
} }
} }

View File

@ -71,7 +71,8 @@ class DNSBLResolver : public Resolver
while(tmp.length()>0) while(tmp.length()>0)
{ {
std::string octet; std::string octet;
unsigned int lastdot = tmp.rfind("."); /* Fix by brain, npos is -1, so unsigned int will never match */
std::string::size_type lastdot = tmp.rfind(".");
if (lastdot == std::string::npos) if (lastdot == std::string::npos)
{ {

View File

@ -12,6 +12,7 @@
*/ */
#include "inspircd.h" #include "inspircd.h"
#include "exitcodes.h"
#include <sys/epoll.h> #include <sys/epoll.h>
#include "socketengine_epoll.h" #include "socketengine_epoll.h"
@ -25,7 +26,7 @@ EPollEngine::EPollEngine(InspIRCd* Instance) : SocketEngine(Instance)
ServerInstance->Log(SPARSE,"ERROR: this is a fatal error, exiting now."); ServerInstance->Log(SPARSE,"ERROR: this is a fatal error, exiting now.");
printf("ERROR: Could not initialize socket engine. Your kernel probably does not have the proper features."); printf("ERROR: Could not initialize socket engine. Your kernel probably does not have the proper features.");
printf("ERROR: this is a fatal error, exiting now."); printf("ERROR: this is a fatal error, exiting now.");
InspIRCd::Exit(ERROR); InspIRCd::Exit(EXIT_STATUS_SOCKETENGINE);
} }
CurrentSetSize = 0; CurrentSetSize = 0;
} }

View File

@ -12,6 +12,7 @@
*/ */
#include "inspircd.h" #include "inspircd.h"
#include "exitcodes.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/event.h> #include <sys/event.h>
#include <sys/time.h> #include <sys/time.h>
@ -27,7 +28,7 @@ KQueueEngine::KQueueEngine(InspIRCd* Instance) : SocketEngine(Instance)
ServerInstance->Log(SPARSE,"ERROR: this is a fatal error, exiting now."); ServerInstance->Log(SPARSE,"ERROR: this is a fatal error, exiting now.");
printf("ERROR: Could not initialize socket engine. Your kernel probably does not have the proper features."); printf("ERROR: Could not initialize socket engine. Your kernel probably does not have the proper features.");
printf("ERROR: this is a fatal error, exiting now."); printf("ERROR: this is a fatal error, exiting now.");
InspIRCd::Exit(ERROR); InspIRCd::Exit(EXIT_STATUS_SOCKETENGINE);
} }
CurrentSetSize = 0; CurrentSetSize = 0;
} }