Răsfoiți Sursa

accept() fix for HP-UX 11.0

Ethan Galstad 22 ani în urmă
părinte
comite
d8c8f4de25
4 a modificat fișierele cu 77 adăugiri și 15 ștergeri
  1. 1 0
      Changelog
  2. 36 3
      contrib/README.nrpe_check_control
  3. 6 6
      include/dh.h
  4. 34 6
      src/nrpe.c

+ 1 - 0
Changelog

@@ -8,6 +8,7 @@ NRPE Changelog
 - Replaced host access list with TCP wrapper support
 - Removed length restrictions for command names and command lines
 - Configure script patch for getopt_long on Solaris
+- Bug fixes for accept() on HP-UX 11.0
 
 
 2.0 - 09/08/2003

+ 36 - 3
contrib/README.nrpe_check_control

@@ -1,4 +1,37 @@
-------- Forwarded message follows -------
+NOTES:
+------
+
+The service definition below assumes you have a command called "check_tcp" already setup
+in your config files.
+
+The command definition below assumes that the $USER1$ macro is used to define the location
+of your Nagios plugins (i.e. "/usr/local/nagios/libexec") and that the nrpe_check_control
+service is located in that directory.
+
+
+
+SAMPLE CONFIG FILE SNIPPETS:
+----------------------------
+
+define service {
+	host_name	<host name goes here>
+	description	NRPE
+	...
+	event_handler	nrpe_check_control
+	check_command	check_tcp!-p 5666
+        }
+
+define command {
+	command_name	nrpe_check_control
+	command_line	$USER1$/nrpe_check_control $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$ "$HOSTNAME$"
+	}
+
+
+
+
+ORIGINAL EMAIL SNIPPET: 
+-----------------------
+
 Date sent:      	Fri, 30 Mar 2001 18:51:48 -0500
 From:           	adam.bowen@<>
 Subject:        	Event Handler
@@ -8,11 +41,11 @@ I am attaching the source code for an event handler I wrote to
 control checks using nrpe.  I add the following check to all remote hosts
 using nrpe:
 
-service[<host Hame>]=NRPE;0;24x7;3;5;1;<contactgroup>;120;24x7;1;1;0;nrpe_check_control;check_tcp!-p 5666
+<see example above>
 
 I added this line to the commands.cfg file:
 
-command[nrpe_check_control]=$USER2$/nrpe_check_control $SERVICESTATE$ $STATETYPE$ $SERVICEATTEMPT$ "$HOSTNAME$"
+<see example above>
 
 When the NRPE service check listed above has 3 failed connection
 attempts, it will run the nrpe_check_control which will search the

+ 6 - 6
include/dh.h

@@ -4,12 +4,12 @@
 DH *get_dh512()
 	{
 	static unsigned char dh512_p[]={
-		0x97,0xDD,0x59,0x8B,0x26,0x78,0x90,0xB1,0xCD,0x59,0xFD,0xB1,
-		0xE5,0x0E,0x71,0x17,0x89,0xD1,0x4E,0xAC,0x72,0x1E,0x2A,0x91,
-		0x8C,0x53,0xA3,0x8D,0xD8,0x82,0xB6,0x9B,0xBF,0xCF,0xA1,0xA7,
-		0xC4,0x98,0x78,0xC0,0xDB,0xA6,0xB5,0x5F,0xDA,0x05,0xE1,0xDE,
-		0xCE,0x5B,0x77,0xF2,0xD6,0xA3,0x71,0xA2,0x16,0xE8,0xB2,0x06,
-		0xFD,0xDB,0x1F,0x4B,
+		0xB3,0xDB,0x56,0x63,0x38,0x40,0xF6,0x12,0xF6,0x12,0xBD,0xBA,
+		0x2D,0x16,0x1E,0xDA,0x2B,0x06,0xFD,0xEE,0x9D,0x2F,0x91,0x52,
+		0x30,0x2F,0x74,0x9E,0xDE,0xE7,0x8B,0x8E,0x01,0x9C,0xCE,0x52,
+		0x42,0xD9,0xA7,0xAD,0x39,0x6C,0x04,0xD6,0x25,0x9F,0x79,0x63,
+		0xE6,0x71,0xFD,0x66,0x54,0x01,0x61,0xB1,0x57,0xFC,0x9C,0x88,
+		0xD4,0xCB,0x8D,0xE3,
 		};
 	static unsigned char dh512_g[]={
 		0x02,

+ 34 - 6
src/nrpe.c

@@ -4,7 +4,7 @@
  * Copyright (c) 1999-2003 Ethan Galstad (nagios@nagios.org)
  * License: GPL
  *
- * Last Modified: 10-14-2003
+ * Last Modified: 10-23-2003
  *
  * Command line: nrpe -c <config_file> [--inetd | --daemon]
  *
@@ -537,6 +537,9 @@ void wait_for_connections(void){
 	char connecting_host[16];
 	pid_t pid;
 	int flag=1;
+	fd_set fdread;
+	struct timeval timeout;
+	int retval;
 #ifdef HAVE_LIBWRAP
 	struct request_info req;
 #endif
@@ -604,10 +607,38 @@ void wait_for_connections(void){
 
 		/* wait for a connection request */
 	        while(1){
+
+			/* wait until there's something to do */
+			FD_ZERO(&fdread);
+			FD_SET(sock,&fdread);
+			timeout.tv_sec=0;
+			timeout.tv_usec=500000;
+			retval=select(sock+1,&fdread,NULL,&fdread,&timeout);
+
+			/* error */
+			if(retval<0)
+				continue;
+
+			/* accept a new connection request */
 			new_sd=accept(sock,0,0);
-			if(new_sd>=0 || (errno!=EWOULDBLOCK && errno!=EINTR))
+
+			/* some kind of error occurred... */
+			if(new_sd<0){
+
+				/* fix for HP-UX 11.0 - just retry */
+				if(errno==ENOBUFS)
+					continue;
+
+				/* retry */
+				if(errno==EWOULDBLOCK || errno==EINTR)
+					continue;
+
+				/* else handle the error later */
 				break;
-			sleep(1);
+			        }
+
+			/* connection was good */
+			break;
 		        }
 
 		/* child process should handle the connection */
@@ -701,9 +732,6 @@ void wait_for_connections(void){
 		        }
   		}
 
-	/* we shouldn't ever get here... */
-	syslog(LOG_NOTICE,"Terminating");
-
 	return;
 	}