From e70ab8655c183e0a3e446ab84b77baf93b67d6d3 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Mon, 1 Aug 2005 15:22:56 +0000 Subject: [PATCH] Centralize SLAPI initialization into slapi_over_config() --- servers/slapd/slapi/plugin.c | 36 ++--------------------- servers/slapd/slapi/slapi_overlay.c | 44 ++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/servers/slapd/slapi/plugin.c b/servers/slapd/slapi/plugin.c index 823b6328f6..88ecb4c83c 100644 --- a/servers/slapd/slapi/plugin.c +++ b/servers/slapd/slapi/plugin.c @@ -643,15 +643,9 @@ slapi_int_read_config( return 1; } - if ( slapMode & SLAP_TOOL_MODE ) { - /* No SLAPI plugins for tools, yet... */ - /* When we have DB overlays we will support DB plugins */ - return 0; - } - /* automatically instantiate overlay if necessary */ - if ( !overlay_is_inst( be, SLAPI_OVERLAY_NAME ) ) { - if ( overlay_config( be, SLAPI_OVERLAY_NAME ) != 0 ) { + if ( !slapi_over_is_inst( be ) ) { + if ( slapi_over_config( be ) != 0 ) { fprintf( stderr, "Failed to instantiate SLAPI overlay\n"); return -1; } @@ -744,29 +738,3 @@ slapi_int_plugin_unparse( } } -int -slapi_int_initialize(void) -{ - if ( ldap_pvt_thread_mutex_init( &slapi_hn_mutex ) ) { - return -1; - } - - if ( ldap_pvt_thread_mutex_init( &slapi_time_mutex ) ) { - return -1; - } - - if ( ldap_pvt_thread_mutex_init( &slapi_printmessage_mutex ) ) { - return -1; - } - - slapi_log_file = slapi_ch_strdup( LDAP_RUNDIR LDAP_DIRSEP "errors" ); - if ( slapi_log_file == NULL ) { - return -1; - } - - if ( slapi_int_init_object_extensions() != 0 ) { - return -1; - } - - return slapi_int_overlay_init(); -} diff --git a/servers/slapd/slapi/slapi_overlay.c b/servers/slapd/slapi/slapi_overlay.c index e066bfb485..83ba0f9033 100644 --- a/servers/slapd/slapi/slapi_overlay.c +++ b/servers/slapd/slapi/slapi_overlay.c @@ -31,6 +31,7 @@ #ifdef LDAP_SLAPI static slap_overinst slapi; +static int slapi_over_initialized = 0; static int slapi_over_response( Operation *op, SlapReply *rs ); static int slapi_over_cleanup( Operation *op, SlapReply *rs ); @@ -554,6 +555,7 @@ slapi_op_func( Operation *op, SlapReply *rs ) slap_callback cb; int internal_op; int preop_type, postop_type; + BackendDB *be; if ( !slapi_plugins_used ) return SLAP_CB_CONTINUE; @@ -595,7 +597,10 @@ slapi_op_func( Operation *op, SlapReply *rs ) pb = SLAPI_OPERATION_PBLOCK( op ); - rc = slapi_int_call_plugins( op->o_bd, preop_type, pb ); + /* cache backend so we call correct postop plugins */ + be = pb->pb_op->o_bd; + + rc = slapi_int_call_plugins( be, preop_type, pb ); /* * soi_callback is responsible for examining the result code @@ -635,7 +640,7 @@ slapi_op_func( Operation *op, SlapReply *rs ) /* * Call postoperation plugins */ - slapi_int_call_plugins( op->o_bd, postop_type, pb ); + slapi_int_call_plugins( be, postop_type, pb ); cleanup: if ( !internal_op ) { @@ -828,8 +833,8 @@ done: return rc; } -int -slapi_int_overlay_init() +static int +slapi_over_init() { memset( &slapi, 0, sizeof(slapi) ); @@ -854,4 +859,35 @@ slapi_int_overlay_init() return overlay_register( &slapi ); } +int slapi_over_is_inst( BackendDB *be ) +{ + return overlay_is_inst( be, SLAPI_OVERLAY_NAME ); +} + +int slapi_over_config( BackendDB *be ) +{ + if ( slapi_over_initialized == 0 ) { + int rc; + + /* do global initializaiton */ + ldap_pvt_thread_mutex_init( &slapi_hn_mutex ); + ldap_pvt_thread_mutex_init( &slapi_time_mutex ); + ldap_pvt_thread_mutex_init( &slapi_printmessage_mutex ); + + slapi_log_file = slapi_ch_strdup( LDAP_RUNDIR LDAP_DIRSEP "errors" ); + + rc = slapi_int_init_object_extensions(); + if ( rc != 0 ) + return rc; + + rc = slapi_over_init(); + if ( rc != 0 ) + return rc; + + slapi_over_initialized = 1; + } + + return overlay_config( be, SLAPI_OVERLAY_NAME ); +} + #endif /* LDAP_SLAPI */ -- 2.39.5