From a6f1348e26386ed239c0bee4acfc8fbfe6ad7bb1 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/OpenSRF/trunk@686 9efc2488-bf62-4759-914b-345cdb29e865 --- src/libstack/osrf_application.c | 24 ++++++++++++++++++++++++ src/libstack/osrf_application.h | 5 +++++ src/libstack/osrf_prefork.c | 17 ++++++++++++++--- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/libstack/osrf_application.c b/src/libstack/osrf_application.c index 685c7ab..713a19d 100644 --- a/src/libstack/osrf_application.c +++ b/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/src/libstack/osrf_application.h b/src/libstack/osrf_application.h index a8342d6..dd5a958 100644 --- a/src/libstack/osrf_application.h +++ b/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/src/libstack/osrf_prefork.c b/src/libstack/osrf_prefork.c index 9678d26..f9761d2 100644 --- a/src/libstack/osrf_prefork.c +++ b/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.11.0