summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-11-12 22:58:48 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-11-12 22:58:48 +0000
commitb3c2abf41eead7a9aac5820796e9600ced8430df (patch)
treec2fbeb42aae2c48ad71c58f45b275444fc29cfa9
parentceafaa5e7a3f9c6eb78bf2823212ecff92d393c7 (diff)
When some (but not all) of the ports fail to bind on startup, give the user a list of the failed port/ip pairs on the terminal.
Other ircds dont do this, and say 'go read the log'. I say if we can output them to a log, why not the screen? :) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5728 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/inspircd.h5
-rw-r--r--src/configreader.cpp3
-rw-r--r--src/inspircd.cpp11
-rw-r--r--src/socket.cpp7
4 files changed, 21 insertions, 5 deletions
diff --git a/include/inspircd.h b/include/inspircd.h
index ea3194ff2..baa1fb589 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -190,6 +190,9 @@ class FileLogger : public EventHandler
virtual ~FileLogger();
};
+/** A list of failed port bindings, used for informational purposes on startup */
+typedef std::vector<std::pair<std::string, long> > FailedPortList;
+
class XLineManager;
/** The main class of the irc server.
@@ -465,7 +468,7 @@ class InspIRCd : public classbase
* @param found_ports The actual number of ports found in the config, as opposed to the number actually bound
* @return The number of ports actually bound without error
*/
- int BindPorts(bool bail, int &found_ports);
+ int BindPorts(bool bail, int &found_ports, FailedPortList &failed_ports);
/** Returns true if this server has the given port bound to the given address
* @param port The port number
diff --git a/src/configreader.cpp b/src/configreader.cpp
index b8719fcd8..b0f2d6872 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -772,7 +772,8 @@ void ServerConfig::Read(bool bail, userrec* user)
if (!bail)
{
int found_ports;
- ServerInstance->stats->BoundPortCount = ServerInstance->BindPorts(false, found_ports);
+ FailedPortList pl;
+ ServerInstance->stats->BoundPortCount = ServerInstance->BindPorts(false, found_ports, pl);
if (!removed_modules.empty())
for (std::vector<std::string>::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++)
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 9521f1b22..f182f7169 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -183,6 +183,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
: ModCount(-1), duration_m(60), duration_h(60*60), duration_d(60*60*24), duration_w(60*60*24*7), duration_y(60*60*24*365)
{
int found_ports = 0;
+ FailedPortList pl;
modules.resize(255);
factory.resize(255);
@@ -260,7 +261,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
this->AddServerName(Config->ServerName);
CheckDie();
InitializeDisabledCommands(Config->DisabledCommands, this);
- stats->BoundPortCount = BindPorts(true, found_ports);
+ stats->BoundPortCount = BindPorts(true, found_ports, pl);
for(int t = 0; t < 255; t++)
Config->global_implementation[t] = 0;
@@ -299,7 +300,13 @@ InspIRCd::InspIRCd(int argc, char** argv)
if (stats->BoundPortCount != (unsigned int)found_ports)
{
- printf("\nWARNING: Not all your client ports could be bound --\n starting anyway with %ld of %d client ports bound.\n", stats->BoundPortCount, found_ports);
+ printf("\nWARNING: Not all your client ports could be bound --\nstarting anyway with %ld of %d client ports bound.\n\n", stats->BoundPortCount, found_ports);
+ printf("The following %lu port%s failed to bind:\n", found_ports - stats->BoundPortCount, found_ports - stats->BoundPortCount != 1 ? "s" : "");
+ int j = 1;
+ for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
+ {
+ printf("%d.\tIP: %s\tPort: %lu\n", j, i->first.empty() ? "<all>" : i->first.c_str(), (unsigned long)i->second);
+ }
}
/* Add the listening sockets used for client inbound connections
diff --git a/src/socket.cpp b/src/socket.cpp
index 284e51a4a..d5ad7b4ce 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -389,7 +389,7 @@ bool InspIRCd::HasPort(int port, char* addr)
}
/* XXX: Probably belongs in class InspIRCd */
-int InspIRCd::BindPorts(bool bail, int &ports_found)
+int InspIRCd::BindPorts(bool bail, int &ports_found, FailedPortList &failed_ports)
{
char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF];
insp_sockaddr client, server;
@@ -439,6 +439,7 @@ int InspIRCd::BindPorts(bool bail, int &ports_found)
if (fd == ERROR)
{
this->Log(DEBUG,"Bad fd %d binding port [%s:%d]",fd,Config->addrs[count],Config->ports[count]);
+ failed_ports.push_back(std::make_pair(Config->addrs[count],Config->ports[count]));
}
else
{
@@ -451,6 +452,7 @@ int InspIRCd::BindPorts(bool bail, int &ports_found)
shutdown(Config->openSockfd[BoundPortCount]->GetFd(),2);
close(Config->openSockfd[BoundPortCount]->GetFd());
delete Config->openSockfd[BoundPortCount];
+ failed_ports.push_back(std::make_pair(Config->addrs[count],Config->ports[count]));
}
else
BoundPortCount++;
@@ -475,6 +477,7 @@ int InspIRCd::BindPorts(bool bail, int &ports_found)
if (fd == ERROR)
{
this->Log(DEBUG,"Bad fd %d binding port [%s:%d]",fd,Config->addrs[count],Config->ports[count]);
+ failed_ports.push_back(std::make_pair(Config->addrs[count],Config->ports[count]));
}
else
{
@@ -483,6 +486,8 @@ int InspIRCd::BindPorts(bool bail, int &ports_found)
{
BoundPortCount++;
}
+ else
+ failed_ports.push_back(std::make_pair(Config->addrs[count],Config->ports[count]));
}
}
return BoundPortCount;