Page 1 of 1

[Nagios-devel] fix nagios' handling of nonblocking reads

Posted: Fri Jan 09, 2009 3:02 pm
by Guest
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, [email protected], [email protected]
BS Web Services, http://bsws.de
Full-Service ISP - Secure Hosting, Mail and DNS Services
Dedicated Servers, Rootservers, Application Hosting - Hamburg & Amsterdam





This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]