listener: Move error messages to something visible by default.
If a listening port cannot be opened, send error messages to opers with snomask +s and ircd.log, instead of snomask +d and the ioerror log, which both are usually disabled. Also, restore information about what listener is having problems. This was lost when report_error() was replaced.
This commit is contained in:
parent
4229cef34c
commit
40173bcbb3
1 changed files with 47 additions and 20 deletions
|
@ -101,6 +101,20 @@ free_listener(struct Listener *listener)
|
|||
|
||||
#define PORTNAMELEN 6 /* ":31337" */
|
||||
|
||||
/*
|
||||
* get_listener_port - return displayable listener port
|
||||
*/
|
||||
static uint16_t
|
||||
get_listener_port(const struct Listener *listener)
|
||||
{
|
||||
#ifdef RB_IPV6
|
||||
if(listener->addr.ss_family == AF_INET6)
|
||||
return ntohs(((const struct sockaddr_in6 *)&listener->addr)->sin6_port);
|
||||
else
|
||||
#endif
|
||||
return ntohs(((const struct sockaddr_in *)&listener->addr)->sin_port);
|
||||
}
|
||||
|
||||
/*
|
||||
* get_listener_name - return displayable listener name and port
|
||||
* returns "host.foo.org:6667" for a given listener
|
||||
|
@ -109,20 +123,13 @@ const char *
|
|||
get_listener_name(const struct Listener *listener)
|
||||
{
|
||||
static char buf[HOSTLEN + HOSTLEN + PORTNAMELEN + 4];
|
||||
int port = 0;
|
||||
|
||||
s_assert(NULL != listener);
|
||||
if(listener == NULL)
|
||||
return NULL;
|
||||
|
||||
#ifdef RB_IPV6
|
||||
if(listener->addr.ss_family == AF_INET6)
|
||||
port = ntohs(((const struct sockaddr_in6 *)&listener->addr)->sin6_port);
|
||||
else
|
||||
#endif
|
||||
port = ntohs(((const struct sockaddr_in *)&listener->addr)->sin_port);
|
||||
|
||||
rb_snprintf(buf, sizeof(buf), "%s[%s/%u]", me.name, listener->name, port);
|
||||
rb_snprintf(buf, sizeof(buf), "%s[%s/%u]",
|
||||
me.name, listener->name, get_listener_port(listener));
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -141,12 +148,7 @@ show_ports(struct Client *source_p)
|
|||
{
|
||||
sendto_one_numeric(source_p, RPL_STATSPLINE,
|
||||
form_str(RPL_STATSPLINE), 'P',
|
||||
#ifdef RB_IPV6
|
||||
ntohs(listener->addr.ss_family == AF_INET ? ((struct sockaddr_in *)&listener->addr)->sin_port :
|
||||
((struct sockaddr_in6 *)&listener->addr)->sin6_port),
|
||||
#else
|
||||
ntohs(((struct sockaddr_in *)&listener->addr)->sin_port),
|
||||
#endif
|
||||
get_listener_port(listener),
|
||||
IsOperAdmin(source_p) ? listener->name : me.name,
|
||||
listener->ref_count, (listener->active) ? "active" : "disabled",
|
||||
listener->ssl ? " ssl" : "");
|
||||
|
@ -171,6 +173,7 @@ inetport(struct Listener *listener)
|
|||
{
|
||||
rb_fde_t *F;
|
||||
int opt = 1;
|
||||
const char *errstr;
|
||||
|
||||
/*
|
||||
* At first, open a new socket
|
||||
|
@ -200,12 +203,21 @@ inetport(struct Listener *listener)
|
|||
|
||||
if(F == NULL)
|
||||
{
|
||||
ilog_error("opening listener socket");
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"Cannot open socket for listener on port %d",
|
||||
get_listener_port(listener));
|
||||
ilog(L_MAIN, "Cannot open socket for listener %s",
|
||||
get_listener_name(listener));
|
||||
return 0;
|
||||
}
|
||||
else if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus*/
|
||||
{
|
||||
ilog_error("no more connections left for listener");
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"No more connections left for listener on port %d",
|
||||
get_listener_port(listener));
|
||||
ilog(L_MAIN, "No more connections left for listener %s",
|
||||
get_listener_name(listener));
|
||||
rb_close(F);
|
||||
return 0;
|
||||
}
|
||||
|
@ -216,7 +228,12 @@ inetport(struct Listener *listener)
|
|||
*/
|
||||
if(setsockopt(rb_get_fd(F), SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt)))
|
||||
{
|
||||
ilog_error("setting SO_REUSEADDR for listener");
|
||||
errstr = strerror(rb_get_sockerr(F));
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"Cannot set SO_REUSEADDR for listener on port %d: %s",
|
||||
get_listener_port(listener), errstr);
|
||||
ilog(L_MAIN, "Cannot set SO_REUSEADDR for listener %s: %s",
|
||||
get_listener_name(listener), errstr);
|
||||
rb_close(F);
|
||||
return 0;
|
||||
}
|
||||
|
@ -228,14 +245,24 @@ inetport(struct Listener *listener)
|
|||
|
||||
if(bind(rb_get_fd(F), (struct sockaddr *) &listener->addr, GET_SS_LEN(&listener->addr)))
|
||||
{
|
||||
ilog_error("binding listener socket");
|
||||
errstr = strerror(rb_get_sockerr(F));
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"Cannot bind for listener on port %d: %s",
|
||||
get_listener_port(listener), errstr);
|
||||
ilog(L_MAIN, "Cannot bind for listener %s: %s",
|
||||
get_listener_name(listener), errstr);
|
||||
rb_close(F);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(rb_listen(F, RATBOX_SOMAXCONN, listener->defer_accept))
|
||||
{
|
||||
ilog_error("listen()");
|
||||
errstr = strerror(rb_get_sockerr(F));
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"Cannot listen() for listener on port %d: %s",
|
||||
get_listener_port(listener), errstr);
|
||||
ilog(L_MAIN, "Cannot listen() for listener %s: %s",
|
||||
get_listener_name(listener), errstr);
|
||||
rb_close(F);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue