summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-02-19 14:44:32 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-02-19 14:44:32 +0000
commit2a9b0cdd30113ab4926f4b68350d619c015c89a3 (patch)
treec756e270ca7d938d62d09c2ecee9d7c6be34af50
parent45fa01dc79889c68734a7629e8487917cf26a836 (diff)
Added exception handling for module loading
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3240 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/modules.h36
-rw-r--r--src/helperfuncs.cpp64
-rw-r--r--src/inspircd.cpp67
-rw-r--r--src/userprocess.cpp11
-rw-r--r--src/users.cpp18
5 files changed, 154 insertions, 42 deletions
diff --git a/include/modules.h b/include/modules.h
index 1cdbbdeda..e1fb37621 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -93,7 +93,14 @@ typedef std::deque<userrec*> chanuserlist;
#define FOREACH_MOD(y,x) if (Config->global_implementation[y] > 0) { \
for (int _i = 0; _i <= MODCOUNT; _i++) { \
if (Config->implement_lists[_i][y]) \
- modules[_i]->x ; \
+ try \
+ { \
+ modules[_i]->x ; \
+ } \
+ catch (ModuleException modexcept) \
+ { \
+ log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
+ } \
} \
}
@@ -107,10 +114,17 @@ typedef std::deque<userrec*> chanuserlist;
MOD_RESULT = 0; \
for (int _i = 0; _i <= MODCOUNT; _i++) { \
if (Config->implement_lists[_i][y]) {\
- int res = modules[_i]->x ; \
- if (res != 0) { \
- MOD_RESULT = res; \
- break; \
+ try \
+ { \
+ int res = modules[_i]->x ; \
+ if (res != 0) { \
+ MOD_RESULT = res; \
+ break; \
+ } \
+ } \
+ catch (ModuleException modexcept) \
+ { \
+ log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
} \
} \
} \
@@ -272,6 +286,18 @@ class ExtMode : public classbase
ExtMode(char mc, int ty, bool oper, int p_on, int p_off) : modechar(mc), type(ty), needsoper(oper), params_when_on(p_on), params_when_off(p_off), list(false) { };
};
+
+class ModuleException
+{
+ public:
+ virtual ModuleException() {};
+ virtual ~ModuleException() {};
+ virtual char *GetReason()
+ {
+ return "Module threw an exception";
+ }
+};
+
/** Priority types which can be returned from Module::Prioritize()
*/
enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER };
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index fc4ec970f..0255de227 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -135,7 +135,14 @@ void Write_NoFormat(int sock, const char *text)
{
if (Config->GetIOHook(fd_ref_table[sock]->port))
{
- Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ try
+ {
+ Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ }
+ catch (ModuleException modexcept)
+ {
+ log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
+ }
}
else
{
@@ -166,7 +173,14 @@ void Write(int sock,char *text, ...)
{
if (Config->GetIOHook(fd_ref_table[sock]->port))
{
- Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ try
+ {
+ Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ }
+ catch (ModuleException modexcept)
+ {
+ log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
+ }
}
else
{
@@ -188,7 +202,14 @@ void WriteServ_NoFormat(int sock, const char* text)
{
if (Config->GetIOHook(fd_ref_table[sock]->port))
{
- Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ try
+ {
+ Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ }
+ catch (ModuleException modexcept)
+ {
+ log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
+ }
}
else
{
@@ -221,7 +242,14 @@ void WriteServ(int sock, char* text, ...)
{
if (Config->GetIOHook(fd_ref_table[sock]->port))
{
- Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ try
+ {
+ Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ }
+ catch (ModuleException modexcept)
+ {
+ log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
+ }
}
else
{
@@ -243,7 +271,14 @@ void WriteFrom_NoFormat(int sock, userrec *user, const char* text)
{
if (Config->GetIOHook(fd_ref_table[sock]->port))
{
- Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ try
+ {
+ Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ }
+ catch (ModuleException modexcept)
+ {
+ log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
+ }
}
else
{
@@ -276,7 +311,14 @@ void WriteFrom(int sock, userrec *user,char* text, ...)
{
if (Config->GetIOHook(fd_ref_table[sock]->port))
{
- Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ try
+ {
+ Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ }
+ catch (ModuleException modexcept)
+ {
+ log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
+ }
}
else
{
@@ -1340,7 +1382,15 @@ void ShowMOTD(userrec *user)
// only one write operation
if (Config->GetIOHook(user->port))
{
- Config->GetIOHook(user->port)->OnRawSocketWrite(user->fd,(char*)WholeMOTD.c_str(),WholeMOTD.length());
+ try
+ {
+ Config->GetIOHook(user->port)->OnRawSocketWrite(user->fd,(char*)WholeMOTD.c_str(),WholeMOTD.length());
+ }
+ catch (ModuleException modexcept)
+ {
+ log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
+ }
+
}
else
{
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 30ff72c41..de9f64781 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -492,35 +492,43 @@ bool InspIRCd::LoadModule(const char* filename)
snprintf(MODERR,MAXBUF,"Loader/Linker error: %s",factory[MODCOUNT+1]->LastError());
return false;
}
- if (factory[MODCOUNT+1]->factory)
- {
- Module* m = factory[MODCOUNT+1]->factory->CreateModule(MyServer);
- modules[MODCOUNT+1] = m;
- /* save the module and the module's classfactory, if
- * this isnt done, random crashes can occur :/ */
- Config->module_names.push_back(filename);
-
- char* x = &Config->implement_lists[MODCOUNT+1][0];
- for(int t = 0; t < 255; t++)
- x[t] = 0;
+ try
+ {
+ if (factory[MODCOUNT+1]->factory)
+ {
+ Module* m = factory[MODCOUNT+1]->factory->CreateModule(MyServer);
+ modules[MODCOUNT+1] = m;
+ /* save the module and the module's classfactory, if
+ * this isnt done, random crashes can occur :/ */
+ Config->module_names.push_back(filename);
+
+ char* x = &Config->implement_lists[MODCOUNT+1][0];
+ for(int t = 0; t < 255; t++)
+ x[t] = 0;
- modules[MODCOUNT+1]->Implements(x);
+ modules[MODCOUNT+1]->Implements(x);
- for(int t = 0; t < 255; t++)
- {
- Config->global_implementation[t] += Config->implement_lists[MODCOUNT+1][t];
- if (Config->implement_lists[MODCOUNT+1][t])
+ for(int t = 0; t < 255; t++)
{
- log(DEBUG,"Add global implementation: %d %d => %d",MODCOUNT+1,t,Config->global_implementation[t]);
+ Config->global_implementation[t] += Config->implement_lists[MODCOUNT+1][t];
+ if (Config->implement_lists[MODCOUNT+1][t])
+ {
+ log(DEBUG,"Add global implementation: %d %d => %d",MODCOUNT+1,t,Config->global_implementation[t]);
+ }
}
- }
- }
- else
- {
- log(DEFAULT,"Unable to load %s",modfile);
- snprintf(MODERR,MAXBUF,"Factory function failed!");
- return false;
- }
+ }
+ else
+ {
+ log(DEFAULT,"Unable to load %s",modfile);
+ snprintf(MODERR,MAXBUF,"Factory function failed!");
+ return false;
+ }
+ }
+ catch (ModuleException modexcept)
+ {
+ log(DEFAULT,"Unable to load %s: ",modfile,modexcept.GetReason());
+ snprintf(MODERR,MAXBUF,"Factory function threw an exception: %s",modexcept.GetReason());
+ }
#ifndef STATIC_LINK
}
else
@@ -742,7 +750,14 @@ int InspIRCd::Run()
NonBlocking(incomingSockfd);
if (Config->GetIOHook(in_port))
{
- Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, (char*)inet_ntoa(client.sin_addr), in_port);
+ try
+ {
+ Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, (char*)inet_ntoa(client.sin_addr), in_port);
+ }
+ catch (ModuleException modexcept)
+ {
+ log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
+ }
}
stats->statsAccept++;
AddClient(incomingSockfd, in_port, false, client.sin_addr);
diff --git a/src/userprocess.cpp b/src/userprocess.cpp
index 5452b8f9e..888d0572f 100644
--- a/src/userprocess.cpp
+++ b/src/userprocess.cpp
@@ -88,8 +88,15 @@ void ProcessUser(userrec* cu)
if (Config->GetIOHook(cu->port))
{
int result2 = 0;
- int MOD_RESULT = Config->GetIOHook(cu->port)->OnRawSocketRead(cu->fd,data,65535,result2);
- log(DEBUG,"Data result returned by module: %d",MOD_RESULT);
+ try
+ {
+ int MOD_RESULT = Config->GetIOHook(cu->port)->OnRawSocketRead(cu->fd,data,65535,result2);
+ log(DEBUG,"Data result returned by module: %d",MOD_RESULT);
+ }
+ catch (ModuleException modexcept)
+ {
+ log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
+ }
if (MOD_RESULT < 0)
{
result = -EAGAIN;
diff --git a/src/users.cpp b/src/users.cpp
index 15663a7d1..f2aa4950f 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -409,7 +409,14 @@ void kill_link(userrec *user,const char* r)
{
if (Config->GetIOHook(user->port))
{
- Config->GetIOHook(user->port)->OnRawSocketClose(user->fd);
+ try
+ {
+ Config->GetIOHook(user->port)->OnRawSocketClose(user->fd);
+ }
+ catch (ModuleException modexcept)
+ {
+ log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
+ }
}
ServerInstance->SE->DelFd(user->fd);
user->CloseSocket();
@@ -472,7 +479,14 @@ void kill_link_silent(userrec *user,const char* r)
{
if (Config->GetIOHook(user->port))
{
- Config->GetIOHook(user->port)->OnRawSocketClose(user->fd);
+ try
+ {
+ Config->GetIOHook(user->port)->OnRawSocketClose(user->fd);
+ }
+ catch (ModuleException modexcept)
+ {
+ log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \
+ }
}
ServerInstance->SE->DelFd(user->fd);
user->CloseSocket();