X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fconnection.c;h=062734c449a27fcad000d355bca39f6b60e179cf;hb=6a9c44849c1c20b9d961de7a0b6585dcd059154a;hp=40dbb8f62e362fb92add97d499fb19e43a55944f;hpb=d2fc667fe7711aa78284caa040724141233b0c57;p=openldap diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 40dbb8f62e..062734c449 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -1,7 +1,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2006 The OpenLDAP Foundation. + * Copyright 1998-2007 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -747,11 +747,12 @@ connection_destroy( Connection *c ) slapd_remove( sd, sb, 1, 0, 0 ); if ( close_reason == NULL ) { - close_reason = ""; + Statslog( LDAP_DEBUG_STATS, "conn=%lu fd=%ld closed\n", + connid, (long) sd, 0, 0, 0 ); + } else { + Statslog( LDAP_DEBUG_STATS, "conn=%lu fd=%ld closed (%s)\n", + connid, (long) sd, close_reason, 0, 0 ); } - - Statslog( LDAP_DEBUG_STATS, "conn=%lu fd=%ld closed (%s)\n", - connid, (long) sd, close_reason, 0, 0 ); } } @@ -1110,7 +1111,7 @@ connection_operation( void *ctx, void *arg_v ) #endif memsiz = SLAP_SLAB_SIZE; - memctx = slap_sl_mem_create( memsiz, SLAP_SLAB_STACK, ctx ); + memctx = slap_sl_mem_create( memsiz, SLAP_SLAB_STACK, ctx, 1 ); op->o_tmpmemctx = memctx; op->o_tmpmfuncs = &slap_sl_mfuncs; if ( tag != LDAP_REQ_ADD && tag != LDAP_REQ_MODIFY ) { @@ -1527,11 +1528,11 @@ connection_input( Connection *conn ) ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd ); - Debug( LDAP_DEBUG_TRACE, - "ber_get_next on fd %d failed errno=%d (%s)\n", - sd, err, sock_errstr(err) ); if ( err != EWOULDBLOCK && err != EAGAIN ) { /* log, close and send error */ + Debug( LDAP_DEBUG_TRACE, + "ber_get_next on fd %d failed errno=%d (%s)\n", + sd, err, sock_errstr(err) ); ber_free( conn->c_currentber, 1 ); conn->c_currentber = NULL; @@ -1945,11 +1946,51 @@ int connection_write(ber_socket_t s) return 0; } +#ifdef LDAP_SLAPI +typedef struct conn_fake_extblock { + void *eb_conn; + void *eb_op; +} conn_fake_extblock; + +static void +connection_fake_destroy( + void *key, + void *data ) +{ + Connection conn = {0}; + Operation op = {0}; + Opheader ohdr = {0}; + + conn_fake_extblock *eb = data; + + op.o_hdr = &ohdr; + op.o_hdr->oh_extensions = eb->eb_op; + conn.c_extensions = eb->eb_conn; + op.o_conn = &conn; + conn.c_connid = -1; + op.o_connid = -1; + + ber_memfree_x( eb, NULL ); + slapi_int_free_object_extensions( SLAPI_X_EXT_OPERATION, &op ); + slapi_int_free_object_extensions( SLAPI_X_EXT_CONNECTION, &conn ); +} +#endif + void connection_fake_init( Connection *conn, Operation *op, void *ctx ) +{ + connection_fake_init2( conn, op, ctx, 1 ); +} + +void +connection_fake_init2( + Connection *conn, + Operation *op, + void *ctx, + int newmem ) { conn->c_connid = -1; conn->c_send_ldap_result = slap_send_ldap_result; @@ -1963,7 +2004,8 @@ connection_fake_init( op->o_hdr = (Opheader *)(op+1); op->o_controls = (void **)(op->o_hdr+1); /* set memory context */ - op->o_tmpmemctx = slap_sl_mem_create(SLAP_SLAB_SIZE, SLAP_SLAB_STACK, ctx); + op->o_tmpmemctx = slap_sl_mem_create(SLAP_SLAB_SIZE, SLAP_SLAB_STACK, ctx, + newmem ); op->o_tmpmfuncs = &slap_sl_mfuncs; op->o_threadctx = ctx; op->o_tid = ldap_pvt_thread_pool_tid( ctx ); @@ -1973,8 +2015,24 @@ connection_fake_init( connection_init_log_prefix( op ); #ifdef LDAP_SLAPI - slapi_int_create_object_extensions( SLAPI_X_EXT_CONNECTION, conn ); - slapi_int_create_object_extensions( SLAPI_X_EXT_OPERATION, op ); + if ( slapi_plugins_used ) { + conn_fake_extblock *eb = NULL; + + /* Use thread keys to make sure these eventually get cleaned up */ + if ( ldap_pvt_thread_pool_getkey( ctx, connection_fake_init, &eb, + NULL )) { + eb = ch_malloc( sizeof( *eb )); + slapi_int_create_object_extensions( SLAPI_X_EXT_CONNECTION, conn ); + slapi_int_create_object_extensions( SLAPI_X_EXT_OPERATION, op ); + eb->eb_conn = conn->c_extensions; + eb->eb_op = op->o_hdr->oh_extensions; + ldap_pvt_thread_pool_setkey( ctx, connection_fake_init, eb, + connection_fake_destroy ); + } else { + conn->c_extensions = eb->eb_conn; + op->o_hdr->oh_extensions = eb->eb_op; + } + } #endif /* LDAP_SLAPI */ slap_op_time( &op->o_time, &op->o_tincr );