Return-Path: Delivered-To: apmail-apache-cvs-archive@apache.org Received: (qmail 4637 invoked by uid 500); 18 Aug 2001 19:22:43 -0000 Mailing-List: contact apache-cvs-help@apache.org; run by ezmlm Precedence: bulk Reply-To: new-httpd@apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list apache-cvs@apache.org Received: (qmail 4624 invoked by uid 500); 18 Aug 2001 19:22:43 -0000 Delivered-To: apmail-httpd-2.0-cvs@apache.org Date: 18 Aug 2001 19:18:12 -0000 Message-ID: <20010818191812.40009.qmail@icarus.apache.org> From: minfrin@apache.org To: httpd-2.0-cvs@apache.org Subject: cvs commit: httpd-2.0/modules/ldap util_ldap.c X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N Status: O X-Status: X-Keywords: X-UID: 302 minfrin 01/08/18 12:18:12 Modified: . CHANGES include util_ldap.h modules/ldap util_ldap.c Log: Fixed LDAP cleanup on graceful restarts. LDAP connections are now cleaned up when the connection pool pool is cleaned up. Revision Changes Path 1.311 +4 -0 httpd-2.0/CHANGES Index: CHANGES =================================================================== RCS file: /home/cvs/httpd-2.0/CHANGES,v retrieving revision 1.310 retrieving revision 1.311 diff -u -r1.310 -r1.311 --- CHANGES 2001/08/18 17:36:26 1.310 +++ CHANGES 2001/08/18 19:18:12 1.311 @@ -1,5 +1,9 @@ Changes with Apache 2.0.25-dev + *) Fixed LDAP cleanup on graceful restarts. LDAP connections are now + cleaned up when the connection pool pool is cleaned up. + [Graham Leggett] + *) Fix a minor issue with Jeff Trawick's mod_include patch. Without this patch, the code will just allocate more bytes in get_combined_directive than are needed. 1.2 +12 -1 httpd-2.0/include/util_ldap.h Index: util_ldap.h =================================================================== RCS file: /home/cvs/httpd-2.0/include/util_ldap.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- util_ldap.h 2001/08/18 16:52:02 1.1 +++ util_ldap.h 2001/08/18 19:18:12 1.2 @@ -90,6 +90,7 @@ /* Structure representing an LDAP connection */ typedef struct util_ldap_connection_t { LDAP *ldap; + apr_pool_t *pool; /* Pool from which this connection is created */ apr_lock_t *lock; /* Lock to indicate this connection is in use */ int bound; /* Flag to indicate whether this connection is bound yet */ @@ -145,13 +146,23 @@ /** * Close a connection to an LDAP server * @param ldc A structure containing the expanded details of the server - that was connected. + * that was connected. * @tip This function unbinds from the LDAP server, and clears ldc->ldap. * It is possible to rebind to this server again using the same ldc * structure, using apr_ldap_open_connection(). * @deffunc util_ldap_close_connection(util_ldap_connection_t *ldc) */ void util_ldap_connection_close(util_ldap_connection_t *ldc); + +/** + * Destroy a connection to an LDAP server + * @param ldc A structure containing the expanded details of the server + * that was connected. + * @tip This function is registered with the pool cleanup to close down the + * LDAP connections when the server is finished with them. + * @deffunc apr_status_t util_ldap_connection_destroy(util_ldap_connection_t *ldc) + */ +apr_status_t util_ldap_connection_destroy(void *param); /** * Find a connection in a list of connections 1.2 +26 -14 httpd-2.0/modules/ldap/util_ldap.c Index: util_ldap.c =================================================================== RCS file: /home/cvs/httpd-2.0/modules/ldap/util_ldap.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- util_ldap.c 2001/08/18 16:43:27 1.1 +++ util_ldap.c 2001/08/18 19:18:12 1.2 @@ -182,14 +182,9 @@ /* - * Closes an LDAP connection by unbinding. Sets the boundas value for the - * http connection config record and clears the bound dn string in the - * global connection record. The next time util_ldap_connection_open() is - * called, the connection will be recreated. - * - * If the log parameter is set, adds a debug entry to the log that the - * server was down and it's reconnecting. - * + * Closes an LDAP connection by unlocking it. The next time + * util_ldap_connection_find() is called this connection will be + * available for reuse. */ void util_ldap_connection_close(util_ldap_connection_t *ldc) { @@ -205,19 +200,32 @@ * we don't have to... */ - /* unbinding from the LDAP server */ -/* FIXME: add this to pool cleanup instead */ + /* mark our connection as available for reuse */ + apr_lock_release(ldc->lock); + +} + + /* + * Destroys an LDAP connection by unbinding. This function is registered + * with the pool cleanup function - causing the LDAP connections to be + * shut down cleanly on thread exit. + */ +apr_status_t util_ldap_connection_destroy(void *param) +{ + util_ldap_connection_t *ldc = param; + + /* unbinding from the LDAP server */ if (ldc->ldap) { ldap_unbind_s(ldc->ldap); ldc->bound = 0; ldc->ldap = NULL; } -*/ - /* mark our connection as available for reuse */ + /* release the lock we were using */ apr_lock_release(ldc->lock); + return APR_SUCCESS; } @@ -226,8 +234,6 @@ * connected (i.e. ldc->ldap is non-NULL.) Does not bind if already bound. * * Returns LDAP_SUCCESS on success; and an error code on failure - * XXX FIXME: Make these APR error codes, not LDAP error codes - * */ int util_ldap_connection_open(util_ldap_connection_t *ldc) { @@ -251,6 +257,11 @@ return -1; } + /* add the cleanup to the pool */ + apr_pool_cleanup_register(ldc->pool, ldc, + util_ldap_connection_destroy, + apr_pool_cleanup_null); + /* Set the alias dereferencing option */ #if LDAP_VERSION_MAX == 2 ldc->ldap->ld_deref = ldc->deref; @@ -443,6 +454,7 @@ l = apr_pcalloc(st->pool, sizeof(util_ldap_connection_t)); apr_lock_create(&l->lock, APR_MUTEX, APR_INTRAPROCESS, NULL, st->pool); apr_lock_acquire(l->lock); + l->pool = st->pool; l->bound = 0; l->host = apr_pstrdup(st->pool, host); l->port = port;