[Opensrf-commits] r2102 - branches/rel_2_0/src/libopensrf (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Nov 22 17:22:07 EST 2010
Author: erickson
Date: 2010-11-22 17:22:01 -0500 (Mon, 22 Nov 2010)
New Revision: 2102
Modified:
branches/rel_2_0/src/libopensrf/osrf_prefork.c
Log:
in the rare case the select() is interrupted while waiting on child statuses, exit early to prevent read()'s on invalid file handles and allow the calling code to loop back around and try again
Modified: branches/rel_2_0/src/libopensrf/osrf_prefork.c
===================================================================
--- branches/rel_2_0/src/libopensrf/osrf_prefork.c 2010-11-22 22:21:35 UTC (rev 2101)
+++ branches/rel_2_0/src/libopensrf/osrf_prefork.c 2010-11-22 22:22:01 UTC (rev 2102)
@@ -92,7 +92,7 @@
static void add_prefork_child( prefork_simple* forker, prefork_child* child );
static void del_prefork_child( prefork_simple* forker, pid_t pid );
-static void check_children( prefork_simple* forker, int forever );
+static int check_children( prefork_simple* forker, int forever );
static int prefork_child_process_request( prefork_child*, char* data );
static int prefork_child_init_hook( prefork_child* );
static prefork_child* prefork_child_init( prefork_simple* forker,
@@ -718,9 +718,12 @@
while( ! honored ) {
- if( !no_recheck )
- check_children( forker, 0 );
- no_recheck = 0;
+ if( !no_recheck ) {
+ if(check_children( forker, 0 ) < 0) {
+ continue; // check failed, try again
+ }
+ }
+ no_recheck = 0;
osrfLogDebug( OSRF_LOG_MARK, "Server received inbound data" );
@@ -800,9 +803,10 @@
if( !honored ) {
osrfLogWarning( OSRF_LOG_MARK, "No children available, waiting..." );
- check_children( forker, 1 );
- // Tell the loop not to call check_children again, since we're calling it now
- no_recheck = 1;
+ if( check_children( forker, 1 ) >= 0 ) {
+ // Tell the loop not to call check_children again, since we just successfully called it
+ no_recheck = 1;
+ }
}
if( child_dead )
@@ -816,14 +820,11 @@
}
-/* XXX Add a flag which tells select() to wait forever on children
- in the best case, this will be faster than calling usleep(x), and
- in the worst case it won't be slower and will do less logging...
-*/
/**
@brief See if any children have become available.
@param forker Pointer to the prefork_simple that owns the children.
@param forever Boolean: true if we should wait indefinitely.
+ @return 0 or greater if successful, -1 on select error/interrupt
Call select() for all the children in the active list. Read each active file
descriptor and move the corresponding child to the idle list.
@@ -831,7 +832,7 @@
If @a forever is true, wait indefinitely for input. Otherwise return immediately if
there are no active file descriptors.
*/
-static void check_children( prefork_simple* forker, int forever ) {
+static int check_children( prefork_simple* forker, int forever ) {
if( child_dead )
reap_children( forker );
@@ -842,7 +843,7 @@
// If forever is false, then the children may all be idle, and that's okay.
if( forever )
osrfLogError( OSRF_LOG_MARK, "No active child processes to check" );
- return;
+ return 0;
}
int select_ret;
@@ -885,8 +886,8 @@
}
}
- if( select_ret == 0 )
- return;
+ if( select_ret <= 0 ) // we're done here
+ return select_ret;
// Check each child in the active list.
// If it has responded, move it to the idle list.
@@ -930,6 +931,8 @@
}
cur_child = next_child;
} while( forker->first_child && forker->first_child != next_child );
+
+ return select_ret;
}
/**
More information about the opensrf-commits
mailing list