[Opensrf-commits] r1278 - trunk/src/libopensrf
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Mar 10 10:05:31 EDT 2008
Author: miker
Date: 2008-03-10 09:32:28 -0400 (Mon, 10 Mar 2008)
New Revision: 1278
Modified:
trunk/src/libopensrf/osrf_prefork.c
Log:
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.
Modified: trunk/src/libopensrf/osrf_prefork.c
===================================================================
--- trunk/src/libopensrf/osrf_prefork.c 2008-03-10 13:10:59 UTC (rev 1277)
+++ trunk/src/libopensrf/osrf_prefork.c 2008-03-10 13:32:28 UTC (rev 1278)
@@ -66,7 +66,7 @@
/* 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 @@
/* 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 @@
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 );
More information about the opensrf-commits
mailing list