From 1580c701aedeadaa2c864f81b96bb38fc5461b31 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Mon, 29 Jan 2007 15:51:18 +0000 Subject: fixed too-low listen backlog parameter --- syslogd.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'syslogd.c') diff --git a/syslogd.c b/syslogd.c index 89a6bfdd..a0d8f30b 100644 --- a/syslogd.c +++ b/syslogd.c @@ -1173,7 +1173,7 @@ static int create_tcp_socket(void) fd = socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) { - logerror("syslog: TCP: Unknown protocol, suspending tcp inet service."); + logerror("syslog: TCP: could not create socket, suspending tcp inet service."); return fd; } @@ -1214,11 +1214,19 @@ static int create_tcp_socket(void) close(fd); return -1; } - - if(listen(fd, 5) < 0) { - logerror("listen, suspending tcp inet"); - close(fd); - return -1; + if(listen(fd, TCPSESS_MAX / 10 + 5) < 0) { + /* If the listen fails, it most probably fails because we ask + * for a too-large backlog. So in this case we first set back + * to a fixed, reasonable, limit that should work. Only if + * that fails, too, we give up. + */ + logerrorInt("listen with a backlog of %d failed - retrying with default of 32.", + TCPSESS_MAX / 10 + 5); + if(listen(fd, 32) < 0) { + logerror("listen, suspending tcp inet"); + close(fd); + return -1; + } } sockTCPLstn = fd; -- cgit