From 805b7d3effc71d44665c0a7f590343c84e03db92 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sun, 7 Jul 2013 16:25:11 +0100 Subject: Fix low risk crash when we can't determine maximum open socket count. --- src/inspircd.cpp | 2 +- src/socketengines/socketengine_epoll.cpp | 4 ++-- src/socketengines/socketengine_kqueue.cpp | 4 ++-- src/socketengines/socketengine_poll.cpp | 2 +- src/socketengines/socketengine_ports.cpp | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 1403cdef5..9516449a0 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -241,7 +241,7 @@ void InspIRCd::SetSignals() void InspIRCd::QuickExit(int status) { - exit(0); + exit(status); } bool InspIRCd::DaemonSeed() diff --git a/src/socketengines/socketengine_epoll.cpp b/src/socketengines/socketengine_epoll.cpp index f7e107e7b..6913076a2 100644 --- a/src/socketengines/socketengine_epoll.cpp +++ b/src/socketengines/socketengine_epoll.cpp @@ -63,7 +63,7 @@ EPollEngine::EPollEngine() { ServerInstance->Logs->Log("SOCKET", DEFAULT, "ERROR: Can't determine maximum number of open sockets!"); std::cout << "ERROR: Can't determine maximum number of open sockets!" << std::endl; - ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE); + ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE); } // This is not a maximum, just a hint at the eventual number of sockets that may be polled. @@ -75,7 +75,7 @@ EPollEngine::EPollEngine() ServerInstance->Logs->Log("SOCKET",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->Exit(EXIT_STATUS_SOCKETENGINE); + ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE); } ref = new EventHandler* [GetMaxFds()]; diff --git a/src/socketengines/socketengine_kqueue.cpp b/src/socketengines/socketengine_kqueue.cpp index e24146943..8694a0bdd 100644 --- a/src/socketengines/socketengine_kqueue.cpp +++ b/src/socketengines/socketengine_kqueue.cpp @@ -74,7 +74,7 @@ KQueueEngine::KQueueEngine() { ServerInstance->Logs->Log("SOCKET", DEFAULT, "ERROR: Can't determine maximum number of open sockets!"); std::cout << "ERROR: Can't determine maximum number of open sockets!" << std::endl; - ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE); + ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE); } this->RecoverFromFork(); @@ -97,7 +97,7 @@ void KQueueEngine::RecoverFromFork() ServerInstance->Logs->Log("SOCKET",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->Exit(EXIT_STATUS_SOCKETENGINE); + ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE); } CurrentSetSize = 0; } diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp index 5c361a0cb..4f4f60b4e 100644 --- a/src/socketengines/socketengine_poll.cpp +++ b/src/socketengines/socketengine_poll.cpp @@ -107,7 +107,7 @@ PollEngine::PollEngine() { ServerInstance->Logs->Log("SOCKET", DEFAULT, "ERROR: Can't determine maximum number of open sockets: %s", strerror(errno)); std::cout << "ERROR: Can't determine maximum number of open sockets: " << strerror(errno) << std::endl; - ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE); + ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE); } #endif diff --git a/src/socketengines/socketengine_ports.cpp b/src/socketengines/socketengine_ports.cpp index 52d799ddf..f7c547d45 100644 --- a/src/socketengines/socketengine_ports.cpp +++ b/src/socketengines/socketengine_ports.cpp @@ -77,7 +77,7 @@ PortsEngine::PortsEngine() { ServerInstance->Logs->Log("SOCKET", DEFAULT, "ERROR: Can't determine maximum number of open sockets!"); std::cout << "ERROR: Can't determine maximum number of open sockets!" << std::endl; - ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE); + ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE); } EngineHandle = port_create(); @@ -87,7 +87,7 @@ PortsEngine::PortsEngine() ServerInstance->Logs->Log("SOCKET",SPARSE,"ERROR: This is a fatal error, exiting now."); std::cout << "ERROR: Could not initialize socket engine: " << strerror(errno) << std::endl; std::cout << "ERROR: This is a fatal error, exiting now." << std::endl; - ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE); + ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE); } CurrentSetSize = 0; -- cgit v1.2.3 From 525a104ef8a639c254d8960b620fe3eb22b34667 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sun, 7 Jul 2013 16:33:31 +0100 Subject: Fix the Poll socket engine on BSD. --- src/socketengines/socketengine_poll.cpp | 42 +++++++++------------------------ 1 file changed, 11 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp index 4f4f60b4e..ea7780686 100644 --- a/src/socketengines/socketengine_poll.cpp +++ b/src/socketengines/socketengine_poll.cpp @@ -35,15 +35,15 @@ #include "socketengine.h" #ifndef _WIN32 - #ifndef __USE_XOPEN - #define __USE_XOPEN /* fuck every fucking OS ever made. needed by poll.h to work.*/ - #endif - #include - #include +# ifndef __USE_XOPEN +# define __USE_XOPEN /* fuck every fucking OS ever made. needed by poll.h to work.*/ +# endif +# include +# include +# include #else - /* *grumble* */ - #define struct pollfd WSAPOLLFD - #define poll WSAPoll +# define struct pollfd WSAPOLLFD +# define poll WSAPoll #endif class InspIRCd; @@ -76,32 +76,13 @@ public: #endif -#ifdef BSD - #include -#else - #include -#endif - PollEngine::PollEngine() { CurrentSetSize = 0; -#ifdef BSD - int mib[2]; - size_t len; - - mib[0] = CTL_KERN; -#ifdef KERN_MAXFILESPERPROC - mib[1] = KERN_MAXFILESPERPROC; -#else - mib[1] = KERN_MAXFILES; -#endif - len = sizeof(MAX_DESCRIPTORS); - sysctl(mib, 2, &MAX_DESCRIPTORS, &len, NULL, 0); -#else - int max = ulimit(4, 0); - if (max > 0) + struct rlimit limits; + if (!getrlimit(RLIMIT_NOFILE, &limits)) { - MAX_DESCRIPTORS = max; + MAX_DESCRIPTORS = limits.rlim_cur; } else { @@ -109,7 +90,6 @@ PollEngine::PollEngine() std::cout << "ERROR: Can't determine maximum number of open sockets: " << strerror(errno) << std::endl; ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE); } -#endif ref = new EventHandler* [GetMaxFds()]; events = new struct pollfd[GetMaxFds()]; -- cgit v1.2.3