]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Deduplicate error handling in the socket engines.
authorPeter Powell <petpow@saberuk.com>
Sun, 22 Oct 2017 02:10:48 +0000 (03:10 +0100)
committerPeter Powell <petpow@saberuk.com>
Sun, 22 Oct 2017 18:45:05 +0000 (19:45 +0100)
include/socketengine.h
src/socketengine.cpp
src/socketengines/socketengine_epoll.cpp
src/socketengines/socketengine_kqueue.cpp
src/socketengines/socketengine_poll.cpp

index 34dd306ba45d5766501ade3a80c4dd075beab9f8..0187a043ed7168adb7cc3b06b4dcdbb4e969b6d6 100644 (file)
@@ -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.
index bac97a6dc3eb6e81f14fb2375cdd38a18e0ee140..58e15af4444bcc936fc353ed164687c3e0ed947f 100644 (file)
  */
 
 
+#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;
index dc10a3613ce7c5c22b117afa1a35ed621a5149f0..60b365ee139027a8cd75482157c7e7a8db9536f4 100644 (file)
 
 
 #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()
index c969af1fdd8b721ba8931eba19a86df2bb076508..b23cfbd9dcf2b6af86a415bac1c9132d7c4ac92a 100644 (file)
 
 
 #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
index c805935882badefa3e5fe3673a8f600a0ba41c21..339045a8c301c5ca75196cb06c90b4d4eb027278 100644 (file)
@@ -21,7 +21,6 @@
  */
 
 
-#include "exitcodes.h"
 #include "inspircd.h"
 
 #include <sys/poll.h>