Commit b19a87a1 authored by rswindell's avatar rswindell
Browse files

Cleaned-up retry_bind(), using LOG_ERR level for last bind attempt failure,

added protocol string argument.
parent 7f67d531
......@@ -4671,12 +4671,11 @@ void DLLCALL ftp_server(void* arg)
if(startup->seteuid!=NULL)
startup->seteuid(FALSE);
result=retry_bind(server_socket, (struct sockaddr *) &server_addr,sizeof(server_addr),startup->bind_retry_count,startup->bind_retry_delay,lprintf);
result=retry_bind(server_socket, (struct sockaddr *) &server_addr,sizeof(server_addr)
,startup->bind_retry_count,startup->bind_retry_delay,"FTP Server",lprintf);
if(startup->seteuid!=NULL)
startup->seteuid(TRUE);
if(result!=0) {
lprintf(LOG_ERR,"%04d !ERROR %d (%d) binding socket to port %u"
,server_socket, result, ERROR_VALUE,startup->port);
lprintf(LOG_ERR,"%04d %s", server_socket, BIND_FAILURE_HELP);
cleanup(1,__LINE__);
return;
......
......@@ -4101,12 +4101,11 @@ void DLLCALL mail_server(void* arg)
if(startup->seteuid!=NULL)
startup->seteuid(FALSE);
result = retry_bind(server_socket,(struct sockaddr *)&server_addr,sizeof(server_addr),startup->bind_retry_count,startup->bind_retry_delay,lprintf);
result = retry_bind(server_socket,(struct sockaddr *)&server_addr,sizeof(server_addr)
,startup->bind_retry_count,startup->bind_retry_delay,"SMTP Server",lprintf);
if(startup->seteuid!=NULL)
startup->seteuid(TRUE);
if(result != 0) {
lprintf(LOG_ERR,"%04d !ERROR %d (%d) binding SMTP socket to port %u"
,server_socket, result, ERROR_VALUE, startup->smtp_port);
lprintf(LOG_ERR,"%04d %s",server_socket, BIND_FAILURE_HELP);
cleanup(1);
return;
......@@ -4149,12 +4148,11 @@ void DLLCALL mail_server(void* arg)
if(startup->seteuid!=NULL)
startup->seteuid(FALSE);
result = retry_bind(pop3_socket,(struct sockaddr *)&server_addr,sizeof(server_addr),startup->bind_retry_count,startup->bind_retry_delay,lprintf);
result = retry_bind(pop3_socket,(struct sockaddr *)&server_addr,sizeof(server_addr)
,startup->bind_retry_count,startup->bind_retry_delay,"POP3 Server",lprintf);
if(startup->seteuid!=NULL)
startup->seteuid(TRUE);
if(result != 0) {
lprintf(LOG_ERR,"%04d !ERROR %d (%d) binding POP3 socket to port %u"
,pop3_socket, result, ERROR_VALUE, startup->pop3_port);
lprintf(LOG_ERR,"%04d %s",pop3_socket,BIND_FAILURE_HELP);
cleanup(1);
return;
......
......@@ -3953,12 +3953,11 @@ void DLLCALL bbs_thread(void* arg)
if(startup->seteuid!=NULL)
startup->seteuid(FALSE);
result = retry_bind(telnet_socket,(struct sockaddr *)&server_addr,sizeof(server_addr),startup->bind_retry_count,startup->bind_retry_delay,lprintf);
result = retry_bind(telnet_socket,(struct sockaddr *)&server_addr,sizeof(server_addr)
,startup->bind_retry_count,startup->bind_retry_delay,"Telnet Server",lprintf);
if(startup->seteuid!=NULL)
startup->seteuid(TRUE);
if(result != 0) {
lprintf(LOG_ERR,"!ERROR %d (%d) binding Telnet socket to port %d"
,result, ERROR_VALUE,startup->telnet_port);
lprintf(LOG_NOTICE,"%s",BIND_FAILURE_HELP);
cleanup(1);
return;
......@@ -3998,12 +3997,11 @@ void DLLCALL bbs_thread(void* arg)
if(startup->seteuid!=NULL)
startup->seteuid(FALSE);
result = retry_bind(rlogin_socket,(struct sockaddr *)&server_addr,sizeof(server_addr),startup->bind_retry_count,startup->bind_retry_delay,lprintf);
result = retry_bind(rlogin_socket,(struct sockaddr *)&server_addr,sizeof(server_addr)
,startup->bind_retry_count,startup->bind_retry_delay,"RLogin Server",lprintf);
if(startup->seteuid!=NULL)
startup->seteuid(TRUE);
if(result != 0) {
lprintf(LOG_ERR,"!ERROR %d (%d) binding RLogin socket to port %d"
,result, ERROR_VALUE,startup->rlogin_port);
lprintf(LOG_NOTICE,"%s",BIND_FAILURE_HELP);
cleanup(1);
return;
......
......@@ -1716,12 +1716,11 @@ void DLLCALL services_thread(void* arg)
if(startup->seteuid!=NULL)
startup->seteuid(FALSE);
result=retry_bind(socket, (struct sockaddr *) &addr, sizeof(addr),startup->bind_retry_count,startup->bind_retry_delay,lprintf);
result=retry_bind(socket, (struct sockaddr *) &addr, sizeof(addr)
,startup->bind_retry_count, startup->bind_retry_delay, service[i].protocol, lprintf);
if(startup->seteuid!=NULL)
startup->seteuid(TRUE);
if(result!=0) {
lprintf(LOG_ERR,"%04d !ERROR %d binding %s socket to port %u"
,socket, ERROR_VALUE, service[i].protocol, service[i].port);
lprintf(LOG_ERR,"%04d %s",socket,BIND_FAILURE_HELP);
close_socket(socket);
continue;
......
......@@ -3090,12 +3090,11 @@ void DLLCALL web_server(void* arg)
if(startup->seteuid!=NULL)
startup->seteuid(FALSE);
result = retry_bind(server_socket,(struct sockaddr *)&server_addr,sizeof(server_addr),startup->bind_retry_count,startup->bind_retry_delay,lprintf);
result = retry_bind(server_socket,(struct sockaddr *)&server_addr,sizeof(server_addr)
,startup->bind_retry_count,startup->bind_retry_delay,"Web Server",lprintf);
if(startup->seteuid!=NULL)
startup->seteuid(TRUE);
if(result != 0) {
lprintf(LOG_ERR,"%04d !ERROR %d (%d) binding socket to port %d"
,server_socket, result, ERROR_VALUE,startup->port);
lprintf(LOG_NOTICE,"%s",BIND_FAILURE_HELP);
cleanup(1);
return;
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2002 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -231,32 +231,30 @@ BOOL socket_check(SOCKET sock, BOOL* rd_p, BOOL* wr_p, DWORD timeout)
return(FALSE);
}
int retry_bind(SOCKET s, const struct sockaddr *addr, socklen_t addrlen, uint retries, uint wait_secs, int (*lprintf)(int level, char *fmt, ...))
int retry_bind(SOCKET s, const struct sockaddr *addr, socklen_t addrlen
,uint retries, uint wait_secs
,const char* prot
,int (*lprintf)(int level, char *fmt, ...))
{
char port_str[128];
int result=-1;
int i;
uint i;
if(addr->sa_family==AF_INET)
SAFEPRINTF(port_str," to port %u",htons(((SOCKADDR_IN *)(addr))->sin_port));
else
port_str[0]=0;
for(i=0;i<=retries;i++) {
result = bind(s,addr,addrlen);
if(result != 0) {
if(lprintf!=NULL) {
if(addr->sa_family==AF_INET) {
lprintf(LOG_WARNING,"%04d !WARNING %d (%d) error binding socket to port %d"
,s, result, ERROR_VALUE,htons(((SOCKADDR_IN *)(addr))->sin_port));
}
else {
lprintf(LOG_WARNING,"%04d !WARNING %d (%d) error binding socket"
,s, result, ERROR_VALUE);
}
}
if(i<retries) {
if(lprintf!=NULL)
lprintf(LOG_WARNING,"%04d Will retry in %d seconds",s ,wait_secs);
SLEEP(wait_secs*1000);
}
}
else
if((result=bind(s,addr,addrlen))==0)
break;
if(lprintf!=NULL)
lprintf(i<retries ? LOG_WARNING:LOG_ERR
,"%04d !ERROR %d binding %s socket%s", s, ERROR_VALUE, prot, port_str);
if(i<retries) {
if(lprintf!=NULL)
lprintf(LOG_WARNING,"%04d Will retry in %u seconds", s, wait_secs);
SLEEP(wait_secs*1000);
}
}
return(result);
}
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2002 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -155,7 +155,9 @@ extern "C" {
int sendfilesocket(int sock, int file, long *offset, long count);
int recvfilesocket(int sock, int file, long *offset, long count);
BOOL socket_check(SOCKET sock, BOOL* rd_p, BOOL* wr_p, DWORD timeout);
int retry_bind(SOCKET s, const struct sockaddr *addr, socklen_t addrlen, uint retries, uint wait_secs, int (*lprintf)(int level, char *fmt, ...));
int retry_bind(SOCKET s, const struct sockaddr *addr, socklen_t addrlen
,uint retries, uint wait_secs, const char* prot
,int (*lprintf)(int level, char *fmt, ...));
#ifdef __cplusplus
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment