summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2017-10-22 03:10:48 +0100
committerPeter Powell <petpow@saberuk.com>2017-10-22 19:45:05 +0100
commit63e300ed082b82530ad5ae0949f45686746b7c9b (patch)
tree652448c5c2bd134df654b49b3aec7d82899abf64
parentb1098712771ab823042fcf8614a706c76c2ff401 (diff)
Deduplicate error handling in the socket engines.
-rw-r--r--include/socketengine.h3
-rw-r--r--src/socketengine.cpp9
-rw-r--r--src/socketengines/socketengine_epoll.cpp11
-rw-r--r--src/socketengines/socketengine_kqueue.cpp11
-rw-r--r--src/socketengines/socketengine_poll.cpp1
5 files changed, 15 insertions, 20 deletions
diff --git a/include/socketengine.h b/include/socketengine.h
index 34dd306ba..0187a043e 100644
--- a/include/socketengine.h
+++ b/include/socketengine.h
@@ -283,6 +283,9 @@ class CoreExport SocketEngine
/** Look up the fd limit using rlimit. */
static void LookupMaxFds();
+ /** Terminates the program when the socket engine fails to initialize. */
+ static void InitError();
+
static void OnSetEvent(EventHandler* eh, int old_mask, int new_mask);
/** Add an event handler to the base socket engine. AddFd(EventHandler*, int) should call this.
diff --git a/src/socketengine.cpp b/src/socketengine.cpp
index bac97a6dc..58e15af44 100644
--- a/src/socketengine.cpp
+++ b/src/socketengine.cpp
@@ -21,8 +21,11 @@
*/
+#include "exitcodes.h"
#include "inspircd.h"
+#include <iostream>
+
/** Reference table, contains all current handlers
**/
std::vector<EventHandler*> SocketEngine::ref;
@@ -60,6 +63,12 @@ void EventHandler::OnEventHandlerError(int errornum)
{
}
+void SocketEngine::InitError()
+{
+ std::cerr << con_red << "FATAL ERROR!" << con_reset << " Socket engine initialization failed. " << strerror(errno) << '.' << std::endl;
+ ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE);
+}
+
void SocketEngine::LookupMaxFds()
{
struct rlimit limits;
diff --git a/src/socketengines/socketengine_epoll.cpp b/src/socketengines/socketengine_epoll.cpp
index dc10a3613..60b365ee1 100644
--- a/src/socketengines/socketengine_epoll.cpp
+++ b/src/socketengines/socketengine_epoll.cpp
@@ -19,11 +19,9 @@
#include "inspircd.h"
-#include "exitcodes.h"
#include <sys/epoll.h>
#include <sys/resource.h>
-#include <iostream>
/** A specialisation of the SocketEngine class, designed to use linux 2.6 epoll().
*/
@@ -43,15 +41,8 @@ void SocketEngine::Init()
// 128 is not a maximum, just a hint at the eventual number of sockets that may be polled,
// and it is completely ignored by 2.6.8 and later kernels, except it must be larger than zero.
EngineHandle = epoll_create(128);
-
if (EngineHandle == -1)
- {
- ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: Could not initialize socket engine: %s", strerror(errno));
- ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: Your kernel probably does not have the proper features. This is a fatal error, exiting now.");
- std::cout << "ERROR: Could not initialize epoll socket engine: " << strerror(errno) << std::endl;
- std::cout << "ERROR: Your kernel probably does not have the proper features. This is a fatal error, exiting now." << std::endl;
- ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE);
- }
+ InitError();
}
void SocketEngine::RecoverFromFork()
diff --git a/src/socketengines/socketengine_kqueue.cpp b/src/socketengines/socketengine_kqueue.cpp
index c969af1fd..b23cfbd9d 100644
--- a/src/socketengines/socketengine_kqueue.cpp
+++ b/src/socketengines/socketengine_kqueue.cpp
@@ -20,11 +20,10 @@
#include "inspircd.h"
-#include "exitcodes.h"
+
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
-#include <iostream>
#include <sys/sysctl.h>
/** A specialisation of the SocketEngine class, designed to use BSD kqueue().
@@ -59,13 +58,7 @@ void SocketEngine::RecoverFromFork()
*/
EngineHandle = kqueue();
if (EngineHandle == -1)
- {
- ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: Could not initialize socket engine. Your kernel probably does not have the proper features.");
- ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: this is a fatal error, exiting now.");
- std::cout << "ERROR: Could not initialize socket engine. Your kernel probably does not have the proper features." << std::endl;
- std::cout << "ERROR: this is a fatal error, exiting now." << std::endl;
- ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE);
- }
+ InitError();
}
/** Shutdown the kqueue engine
diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp
index c80593588..339045a8c 100644
--- a/src/socketengines/socketengine_poll.cpp
+++ b/src/socketengines/socketengine_poll.cpp
@@ -21,7 +21,6 @@
*/
-#include "exitcodes.h"
#include "inspircd.h"
#include <sys/poll.h>