From d60ad23662e7a4045aae31e576ef393bb2cd54b8 Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 10 Mar 2008 13:32:28 +0000 Subject: [PATCH 1/1] Patch from Scott McKellar: 1. Pedantic: I changed child_dead from an int to a sig_atomic_t, since we set it from a signal handler. 2. In check_children() and prefork_child_wait(), we prepare an input buffer for a read() by calling the osrf_clearbuf macro. Depending on the existence of NDEBUG, this macro may or may not do the right thing. If it does the wrong thing, it will pad the input data with exclamation points, up to the maximimum length. I added code to explicitly add a terminal nul, thus rendering the osrf_clearbuf macro both harmless and superfluous. This issue is the same one that I mentioned yesterday in connection with socket_bundle.c, so I shall not belabor it here. 3. In addition: in check_children() I arranged to issue the debug message only if the read is successful. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1278 9efc2488-bf62-4759-914b-345cdb29e865 --- src/libopensrf/osrf_prefork.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libopensrf/osrf_prefork.c b/src/libopensrf/osrf_prefork.c index 850d6df..95ca398 100644 --- a/src/libopensrf/osrf_prefork.c +++ b/src/libopensrf/osrf_prefork.c @@ -66,7 +66,7 @@ static void osrf_prefork_child_exit( prefork_child* ); /* true if we just deleted a child. This will allow us to make sure we're not trying to use freed memory */ -static int child_dead; +static sig_atomic_t child_dead; static void sigchld_handler( int sig ); @@ -634,11 +634,13 @@ static void check_children( prefork_simple* forker, int forever ) { /* now suck off the data */ char buf[64]; osrf_clearbuf( buf, sizeof(buf) ); - if( (n=read(cur_child->read_status_fd, buf, 63)) < 0 ) { + if( (n=read(cur_child->read_status_fd, buf, sizeof(buf) - 1)) < 0 ) { osrfLogWarning( OSRF_LOG_MARK, "Read error after select in child status read with errno %d", errno); } - - osrfLogDebug( OSRF_LOG_MARK, "Read %d bytes from status buffer: %s", n, buf ); + else { + buf[n] = '\0'; + osrfLogDebug( OSRF_LOG_MARK, "Read %d bytes from status buffer: %s", n, buf ); + } cur_child->available = 1; } cur_child = cur_child->next; @@ -661,6 +663,7 @@ static void prefork_child_wait( prefork_child* child ) { clr_fl(child->read_data_fd, O_NONBLOCK ); while( (n=read(child->read_data_fd, buf, READ_BUFSIZE-1)) > 0 ) { + buf[n] = '\0'; osrfLogDebug(OSRF_LOG_MARK, "Prefork child read %d bytes of data", n); if(!gotdata) set_fl(child->read_data_fd, O_NONBLOCK ); -- 2.43.2