From b5d76cbf265680069a2e9c2cf0c5d6b0a1c07c6a Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 11 Apr 2006 15:58:15 +0000 Subject: [PATCH] added child init handling to the C stack git-svn-id: svn://svn.open-ils.org/ILS/trunk@3668 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- OpenSRF/src/libstack/osrf_application.c | 24 ++++++++++++++++++++++++ OpenSRF/src/libstack/osrf_application.h | 5 +++++ OpenSRF/src/libstack/osrf_prefork.c | 17 ++++++++++++++--- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/OpenSRF/src/libstack/osrf_application.c b/OpenSRF/src/libstack/osrf_application.c index 685c7ab81e..713a19d9f7 100644 --- a/OpenSRF/src/libstack/osrf_application.c +++ b/OpenSRF/src/libstack/osrf_application.c @@ -57,6 +57,30 @@ int osrfAppRegisterApplication( char* appName, char* soFile ) { return 0; } +int osrfAppRunChildInit(char* appname) { + osrfApplication* app = _osrfAppFindApplication(appname); + if(!app) return -1; + + char* error; + int ret; + int (*childInit) (void); + + *(void**) (&childInit) = dlsym(app->handle, "osrfAppChildInit"); + + if( (error = dlerror()) != NULL ) { + osrfLogInfo( OSRF_LOG_MARK, "No child init defined for app %s : %s", appname, error); + return 0; + } + + if( (ret = (*childInit)()) ) { + osrfLogError(OSRF_LOG_MARK, "App %s child init failed", appname); + return -1; + } + + osrfLogInfo(OSRF_LOG_MARK, "%s child init succeeded", appname); + return 0; +} + int osrfAppRegisterMethod( char* appName, char* methodName, char* symbolName, char* notes, int argc, int options ) { diff --git a/OpenSRF/src/libstack/osrf_application.h b/OpenSRF/src/libstack/osrf_application.h index a8342d6261..dd5a958cc7 100644 --- a/OpenSRF/src/libstack/osrf_application.h +++ b/OpenSRF/src/libstack/osrf_application.h @@ -216,3 +216,8 @@ int osrfAppIntrospect( osrfMethodContext* ctx ); int osrfAppIntrospectAll( osrfMethodContext* ctx ); +/** + * Tells the backend process to run its child init function */ +int osrfAppRunChildInit(char* appname); + + diff --git a/OpenSRF/src/libstack/osrf_prefork.c b/OpenSRF/src/libstack/osrf_prefork.c index 9678d26e2c..f9761d2249 100644 --- a/OpenSRF/src/libstack/osrf_prefork.c +++ b/OpenSRF/src/libstack/osrf_prefork.c @@ -1,6 +1,7 @@ #include "osrf_prefork.h" #include #include "osrf_app_session.h" +#include "osrf_application.h" /* true if we just deleted a child. This will allow us to make sure we're not trying to use freed memory */ @@ -124,6 +125,12 @@ void prefork_child_init_hook(prefork_child* child) { free(resc); + if( ! osrfAppRunChildInit(child->appname) ) { + osrfLogDebug(OSRF_LOG_MARK, "Prefork child_init succeeded\n"); + } else { + osrfLogError(OSRF_LOG_MARK, "Prefork child_init failed\n"); + } + set_proc_title( "OpenSRF Drone [%s]", child->appname ); } @@ -162,6 +169,9 @@ prefork_simple* prefork_simple_init( transport_client* client, return NULL; } + osrfLogInfo(OSRF_LOG_MARK, "Prefork launching child with max_request=%d," + "min_children=%d, max_children=%d", max_requests, min_children, max_children ); + /* flesh out the struct */ prefork_simple* prefork = (prefork_simple*) safe_malloc(sizeof(prefork_simple)); prefork->max_requests = max_requests; @@ -441,7 +451,7 @@ void prefork_child_wait( prefork_child* child ) { char buf[READ_BUFSIZE]; memset( buf, 0, READ_BUFSIZE ); - for( i = 0; i!= child->max_requests; i++ ) { + for( i = 0; i < child->max_requests; i++ ) { n = -1; clr_fl(child->read_data_fd, O_NONBLOCK ); @@ -466,7 +476,7 @@ void prefork_child_wait( prefork_child* child ) { } if( n < 0 ) { - osrfLogWarning( OSRF_LOG_MARK, "Child read returned error with errno %d", errno ); + osrfLogWarning( OSRF_LOG_MARK, "Prefork child read returned error with errno %d", errno ); break; } @@ -476,7 +486,8 @@ void prefork_child_wait( prefork_child* child ) { buffer_free(gbuf); - osrfLogDebug( OSRF_LOG_MARK, "Child exiting...[%d]", getpid() ); + osrfLogDebug( OSRF_LOG_MARK, "Child with max-requests=%d, num-served=%d exiting...[%d]", + child->max_requests, i, getpid() ); exit(0); } -- 2.43.2