fix nagios' handling of nonblocking reads

Henning Brauer hb-nagios at bsws.de
Fri Jan 9 15:35:27 CET 2009


nagios is doing reads on nonblocking fds incorrectly. easily
observable by using an alert script that sleeps for a long time,
nagios will consume all CPU time as long as the script runs.
the fix is to poll on EAGAIN instead of looping, of course. this has
the nice side effect of reducing overall CPU load caused by the nagios
process considerably.

$OpenBSD$
--- base/utils.c.orig	Fri Jan  9 14:20:10 2009
+++ base/utils.c	Fri Jan  9 14:28:24 2009
@@ -610,8 +610,16 @@ int my_system(char *cmd,int timeout,int *early_timeout
 				/* handle errors */
 				if(bytes_read==-1){
 					/* we encountered a recoverable error, so try again */
-					if(errno==EINTR || errno==EAGAIN)
+					if(errno==EINTR)
 						continue;
+					else if (errno == EAGAIN) {
+						struct pollfd	pfd;
+
+						pfd.fd = fd[0];
+						pfd.revents = POLLIN;
+						poll(&pfd, 1, -1);
+						continue;
+						}
 					else
 						break;
 					}


-- 
Henning Brauer, hb at bsws.de, henning at openbsd.org
BS Web Services, http://bsws.de
Full-Service ISP - Secure Hosting, Mail and DNS Services
Dedicated Servers, Rootservers, Application Hosting - Hamburg & Amsterdam

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB




More information about the Developers mailing list