Просмотр исходного кода

Added listen_queue_size as configuration option (Vadim Antipov, Kaspersky Lab)

Notes from Vadim:

1) While using nrpe as a checker proxy on several Linux hosts in our
company we have noticed problems under high check rate. We have found
the problems were due to a small socket backlog size. This value (5)
is hardcoded in nrpe.c now. So, I propose a new configuration parameter
"listen_queue_size". The change is backward compatible.

2) Minor debug print errors were fixed.
"Connection from %s closed." debug message was broken for allowed IPv4 hosts.
Eric Stanley 12 лет назад
Родитель
Сommit
15fb2cffb3
3 измененных файлов с 38 добавлено и 6 удалено
  1. 5 0
      Changelog
  2. 8 0
      sample-config/nrpe.cfg.in
  3. 25 6
      src/nrpe.c

+ 5 - 0
Changelog

@@ -2,6 +2,11 @@
 NRPE Changelog
 **************
 
+2.16 = xx/xx/xxxx
+-----------------
+ENHANCEMENTS
+- Added listen_queue_size as configuration option (Vadim Antipov, Kaspersky Lab)
+
 2.15 - 09/06/2013
 -----------------
 - Now compiles on HP-UX (Grant Byers)

+ 8 - 0
sample-config/nrpe.cfg.in

@@ -45,6 +45,14 @@ server_port=@nrpe_port@
 
 
 
+# LISTEN QUEUE SIZE
+# Listen queue size (backlog) for serving incoming connections.
+# You may want to increase this value under high load.
+
+#listen_queue_size=5
+
+
+
 # NRPE USER
 # This determines the effective user that the NRPE daemon should run as.  
 # You can either supply a username or a UID.

+ 25 - 6
src/nrpe.c

@@ -56,6 +56,7 @@ int use_ssl=FALSE;
 #define NASTY_METACHARS         "|`&><'\"\\[]{};"
 #define howmany(x,y)	(((x)+((y)-1))/(y))
 #define MAX_LISTEN_SOCKS        16
+#define DEFAULT_LISTEN_QUEUE_SIZE	5
 
 
 char    *command_name=NULL;
@@ -98,6 +99,7 @@ int     show_version=FALSE;
 int     use_inetd=TRUE;
 int     debug=FALSE;
 int     use_src=FALSE; /* Define parameter for SRC option */
+int		listen_queue_size=DEFAULT_LISTEN_QUEUE_SIZE;
 
 
 void complete_SSL_shutdown( SSL *);
@@ -598,6 +600,14 @@ int read_config_file(char *filename){
 		else if(!strcmp(varname,"pid_file"))
 			pid_file=strdup(varvalue);
 
+		else if(!strcmp(varname,"listen_queue_size")){
+			listen_queue_size=atoi(varvalue);
+			if(listen_queue_size == 0){
+				syslog(LOG_ERR,"Invalid listen queue size specified in config file '%s' - Line %d\n",filename,line);
+				return ERROR;
+				}
+			}
+
 		else if(!strcmp(varname,"log_facility")){
 			if((get_log_facility(varvalue))==OK){
 				/* re-open log using new facility */
@@ -859,7 +869,7 @@ void create_listener(struct addrinfo *ai) {
 	num_listen_socks++;
 
 	/* Start listening on the port. */
-	if (listen(listen_sock, 5) < 0) {
+	if (listen(listen_sock, listen_queue_size) < 0) {
 		syslog(LOG_ERR, "listen on [%s]:%s: %.100s", ntop, strport, 
 				strerror(errno));
 		exit(1);
@@ -1131,7 +1141,16 @@ void wait_for_connections(void){
 
 					/* log info to syslog facility */
 					if(debug==TRUE) {
-						syslog(LOG_DEBUG,"Connection from %s closed.",ipstr);
+						switch(addr.ss_family) {
+						case AF_INET:
+							syslog(LOG_DEBUG,"Connection from %s closed.",
+									inet_ntoa(nptr->sin_addr));
+							break;
+						case AF_INET6:
+							syslog(LOG_DEBUG,"Connection from %s closed.",
+									ipstr);
+							break;
+							}
 						}
 
 					/* close socket prior to exiting */
@@ -1276,10 +1295,10 @@ void handle_connection(int sock){
 	        }
 
 #ifdef DEBUG
-	fp=fopen("/tmp/packet","w");
-	if(fp){
-		fwrite(&receive_packet,1,sizeof(receive_packet),fp);
-		fclose(fp);
+	errfp=fopen("/tmp/packet","w");
+	if(errfp){
+		fwrite(&receive_packet,1,sizeof(receive_packet),errfp);
+		fclose(errfp);
 	        }
 #endif