summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-07 21:25:48 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-07 21:25:48 +0000
commit358f2064c432e1e3ef153adeb5aed0fa2e35efde (patch)
tree721353c3c77d93f15bbd9d6fd80df2761b4b6117
parent923586e54c005780edcc5c427bb4698caf16bcf0 (diff)
Bail if we couldn't bind any ports (when did this get broken?)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4774 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--src/inspircd.cpp12
-rw-r--r--src/socket.cpp39
-rw-r--r--src/socketengine_epoll.cpp4
-rw-r--r--src/socketengine_kqueue.cpp3
-rw-r--r--src/socketengine_select.cpp3
5 files changed, 42 insertions, 19 deletions
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index cd5f74a0a..c31dbae50 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -917,7 +917,13 @@ int InspIRCd::Run()
this->BuildISupport();
printf("\nInspIRCd is now running!\n");
-
+
+ if (!stats->BoundPortCount)
+ {
+ printf("\nI couldn't bind any ports! Are you sure you didn't start InspIRCd twice?\n");
+ Exit(ERROR);
+ }
+
if (!Config->nofork)
{
fclose(stdout);
@@ -928,8 +934,12 @@ int InspIRCd::Run()
/* Add the listening sockets used for client inbound connections
* to the socket engine
*/
+ log(DEBUG,"%d listeners",stats->BoundPortCount);
for (unsigned long count = 0; count < stats->BoundPortCount; count++)
+ {
+ log(DEBUG,"Add listener: %d",Config->openSockfd[count]);
SE->AddFd(Config->openSockfd[count],true,X_LISTEN);
+ }
this->WritePID(Config->PID);
diff --git a/src/socket.cpp b/src/socket.cpp
index 1821120f4..cbb2a213c 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -347,19 +347,21 @@ int BindPorts(bool bail)
if ((Config->openSockfd[count] = OpenTCPSocket()) == ERROR)
{
log(DEBUG,"Bad fd %d binding port [%s:%d]",Config->openSockfd[count],Config->addrs[count],Config->ports[count]);
- return ERROR;
- }
- if (!BindSocket(Config->openSockfd[count],client,server,Config->ports[count],Config->addrs[count]))
- {
- log(DEFAULT,"Failed to bind port [%s:%d]: %s",Config->addrs[count],Config->ports[count],strerror(errno));
}
else
{
- /* Associate the new open port with a slot in the socket engine */
- if (Config->openSockfd[count] > -1)
+ if (!BindSocket(Config->openSockfd[count],client,server,Config->ports[count],Config->addrs[count]))
+ {
+ log(DEFAULT,"Failed to bind port [%s:%d]: %s",Config->addrs[count],Config->ports[count],strerror(errno));
+ }
+ else
{
- ServerInstance->SE->AddFd(Config->openSockfd[count],true,X_LISTEN);
- BoundPortCount++;
+ /* Associate the new open port with a slot in the socket engine */
+ if (Config->openSockfd[count] > -1)
+ {
+ ServerInstance->SE->AddFd(Config->openSockfd[count],true,X_LISTEN);
+ BoundPortCount++;
+ }
}
}
}
@@ -403,17 +405,18 @@ int BindPorts(bool bail)
if ((Config->openSockfd[BoundPortCount] = OpenTCPSocket()) == ERROR)
{
log(DEBUG,"Bad fd %d binding port [%s:%d]",Config->openSockfd[BoundPortCount],Config->addrs[count],Config->ports[count]);
- return ERROR;
- }
-
- if (!BindSocket(Config->openSockfd[BoundPortCount],client,server,Config->ports[count],Config->addrs[count]))
- {
- log(DEFAULT,"Failed to bind port [%s:%d]: %s",Config->addrs[count],Config->ports[count],strerror(errno));
}
else
{
- /* well we at least bound to one socket so we'll continue */
- BoundPortCount++;
+ if (!BindSocket(Config->openSockfd[BoundPortCount],client,server,Config->ports[count],Config->addrs[count]))
+ {
+ log(DEFAULT,"Failed to bind port [%s:%d]: %s",Config->addrs[count],Config->ports[count],strerror(errno));
+ }
+ else
+ {
+ /* well we at least bound to one socket so we'll continue */
+ BoundPortCount++;
+ }
}
}
@@ -422,7 +425,7 @@ int BindPorts(bool bail)
{
log(DEFAULT,"No ports bound, bailing!");
printf("\nERROR: Could not bind any of %d ports! Please check your configuration.\n\n", PortCount);
- return ERROR;
+ return 0;
}
return BoundPortCount;
diff --git a/src/socketengine_epoll.cpp b/src/socketengine_epoll.cpp
index d1a761d5b..4afee1374 100644
--- a/src/socketengine_epoll.cpp
+++ b/src/socketengine_epoll.cpp
@@ -55,7 +55,11 @@ bool EPollEngine::AddFd(int fd, bool readable, char type)
log(DEFAULT,"ERROR: System out of file descriptors!");
return false;
}
+ if (ref[fd])
+ return false;
+
ref[fd] = type;
+
if (readable)
{
log(DEBUG,"Set readbit");
diff --git a/src/socketengine_kqueue.cpp b/src/socketengine_kqueue.cpp
index 388a84f29..656c68224 100644
--- a/src/socketengine_kqueue.cpp
+++ b/src/socketengine_kqueue.cpp
@@ -58,6 +58,9 @@ bool KQueueEngine::AddFd(int fd, bool readable, char type)
return false;
}
+ if (ref[fd])
+ return false;
+
ref[fd] = type;
if (readable)
{
diff --git a/src/socketengine_select.cpp b/src/socketengine_select.cpp
index f36c96379..a57da4a31 100644
--- a/src/socketengine_select.cpp
+++ b/src/socketengine_select.cpp
@@ -50,6 +50,9 @@ bool SelectEngine::AddFd(int fd, bool readable, char type)
fds[fd] = fd;
+ if (ref[fd])
+ return false;
+
ref[fd] = type;
if (readable)
{