Page 1 of 1

[Nagios-devel] ndo2db patches for error conditions

Posted: Wed Mar 05, 2008 1:59 am
by Guest

--Apple-Mail-6-918189956
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit

Hi Ethan,

Attached are two patches that we've applied to our copy of ndoutils
1.4b3 (these also apply cleanup on version 1.4b7).


RETRY ON SOFT READ ERRORS

It was possible that if a read() error occurred with errno==EAGAIN or
EINTR, that the code would continue processing with result=-1. This
could cause segfaults as a 0 byte is then attempted to be placed into
buf[-1].

This patch will loop back over the read() call for those soft errors.


REMOVE MULTIPLE CHILDREN

We haven't found exactly which circumstances cause this (maybe the
above?), but we occasionally find defunct ndo2db processes. These
don't get reaped properly as each SIGCHLD call only reaps a single
child. The patch loops around the waitpit() until there are no more
children to reap.


Can you evaluate for inclusion into the next release of ndoutils?


Ton

http://www.altinity.com
UK: +44 (0)870 787 9243
US: +1 866 879 9184
Fax: +44 (0)845 280 1725
Skype: tonvoon


--Apple-Mail-6-918189956
Content-Disposition: attachment;
filename=ndoutils_retry_on_soft_read_errors.patch
Content-Type: application/octet-stream; x-unix-mode=0644;
name="ndoutils_retry_on_soft_read_errors.patch"
Content-Transfer-Encoding: 7bit

diff -ur ndoutils-1.4b3.original/src/ndo2db.c ndoutils-1.4b3/src/ndo2db.c
--- ndoutils-1.4b3.original/src/ndo2db.c 2008-03-04 12:24:00.000000000 +0000
+++ ndoutils-1.4b3/src/ndo2db.c 2008-03-04 14:31:49.609330552 +0000
@@ -804,9 +809,14 @@
result=read(sd,buf,sizeof(buf)-1);

/* bail out on hard errors */
- if(result==-1 && (errno!=EAGAIN && errno!=EINTR)){
- error=NDO_TRUE;
- break;
+ if(result==-1) {
+ /* Altinity patch: EAGAIN and EINTR are soft errors, so try another read() */
+ if (errno==EAGAIN || errno==EINTR)
+ continue;
+ else {
+ error=NDO_TRUE;
+ break;
+ }
}

/* zero bytes read means we lost the connection with the client */

--Apple-Mail-6-918189956
Content-Disposition: attachment;
filename=ndoutils_remove_multiple_children.patch
Content-Type: application/octet-stream; x-unix-mode=0644;
name="ndoutils_remove_multiple_children.patch"
Content-Transfer-Encoding: 7bit

diff -ur ndoutils-1.4b3.original/src/ndo2db.c ndoutils-1.4b3/src/ndo2db.c
--- ndoutils-1.4b3.original/src/ndo2db.c 2008-03-04 12:24:00.301756000 +0000
+++ ndoutils-1.4b3/src/ndo2db.c 2008-03-04 12:49:18.499017960 +0000
@@ -595,10 +595,15 @@


void ndo2db_parent_sighandler(int sig){
+ pid_t childpid=-1;

/* cleanup children that exit, so we don't have zombies */
if(sig==SIGCHLD){
- waitpid(-1,NULL,WNOHANG);
+ /* Altinity patch: Remove multiple children */
+ while((childpid = waitpid(-1,NULL,WNOHANG)) > 0) {
+ }
+ if (childpid == -1 && errno != ECHILD)
+ fprintf(stderr, "Got error from waitpid(). Errno=%d", errno);
return;
}


--Apple-Mail-6-918189956--





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