1 /* conn.c - deal with connection subsystem */
3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
8 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
12 * This work has beed deveolped for the OpenLDAP Foundation
13 * in the hope that it may be useful to the Open Source community,
14 * but WITHOUT ANY WARRANTY.
16 * Permission is granted to anyone to use this software for any purpose
17 * on any computer system, and to alter it and redistribute it, subject
18 * to the following restrictions:
20 * 1. The author and SysNet s.n.c. are not responsible for the consequences
21 * of use of this software, no matter how awful, even if they arise from
24 * 2. The origin of this software must not be misrepresented, either by
25 * explicit claim or by omission. Since few users ever read sources,
26 * credits should appear in the documentation.
28 * 3. Altered versions must be plainly marked as such, and must not be
29 * misrepresented as being the original software. Since few users
30 * ever read sources, credits should appear in the documentation.
31 * SysNet s.n.c. cannot be responsible for the consequences of the
34 * 4. This notice may not be removed or altered.
42 #include "back-monitor.h"
45 monitor_subsys_conn_init(
49 struct monitorinfo *mi;
52 struct berval *bv[2], val;
56 mi = ( struct monitorinfo * )be->be_private;
58 if ( monitor_cache_get( mi,
59 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, &e ) ) {
61 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
62 "monitor_subsys_conn_init: "
63 "unable to get entry '%s'\n",
64 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn ));
66 Debug( LDAP_DEBUG_ANY,
67 "monitor_subsys_conn_init: "
68 "unable to get entry '%s'\n%s%s",
69 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn,
78 monitor_cache_release( mi, e );
84 monitor_subsys_conn_update(
85 struct monitorinfo *mi,
91 int nconns, nwritewaiters, nreadwaiters;
94 struct berval *bv[2], val, **b = NULL;
103 nconns = nwritewaiters = nreadwaiters = 0;
104 for ( c = connection_first( &connindex );
106 c = connection_next( c, &connindex ), nconns++ ) {
107 if ( c->c_writewaiter ) {
110 if ( c->c_currentber != NULL ) {
117 snprintf( buf, sizeof( buf ), "readwaiters=%d", nreadwaiters );
119 if ( ( a = attr_find( e->e_attrs, monitor_ad_desc ) ) != NULL ) {
120 for ( b = a->a_vals; b[0] != NULL; b++ ) {
121 if ( strncmp( b[0]->bv_val, "readwaiters=",
122 sizeof( "readwaiters=" ) - 1 ) == 0 ) {
123 free( b[0]->bv_val );
124 b[0] = ber_bvstrdup( buf );
130 if ( b == NULL || b[0] == NULL ) {
132 val.bv_len = strlen( buf );
133 attr_merge( e, monitor_ad_desc, bv );
146 struct monitorentrypriv *mp;
152 struct berval *bv[2], val;
157 assert( ep != NULL );
159 snprintf( buf, sizeof( buf ),
162 "objectClass: LDAPsubEntry\n"
163 #ifdef SLAPD_MONITORSUBENTRY
164 "objectClass: monitorSubEntry\n"
165 #else /* !SLAPD_MONITORSUBENTRY */
166 "objectClass: extensibleObject\n"
167 #endif /* !SLAPD_MONITORSUBENTRY */
169 c->c_connid, monitor_subsys[SLAPD_MONITOR_CONN].mss_dn,
171 e = str2entry( buf );
175 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
176 "monitor_subsys_conn_create: "
177 "unable to create entry "
178 "'cn=%ld,%s' entry\n",
180 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn ));
182 Debug( LDAP_DEBUG_ANY,
183 "monitor_subsys_conn_create: "
184 "unable to create entry "
185 "'cn=%ld,%s' entry\n%s",
187 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn, "" );
192 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
194 ltm = gmtime( &c->c_starttime );
195 strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
197 ltm = gmtime( &c->c_activitytime );
198 strftime( buf3, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
200 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
208 ": %s : %s : %s : %s",
210 (long) c->c_protocol,
211 c->c_n_ops_received, c->c_n_ops_executing,
212 c->c_n_ops_pending, c->c_n_ops_completed,
214 /* add low-level counters here */
215 c->c_n_get, c->c_n_read, c->c_n_write,
217 c->c_currentber ? "r" : "",
218 c->c_writewaiter ? "w" : "",
219 c->c_ops != NULL ? "x" : "",
220 c->c_pending_ops != NULL ? "p" : "",
221 connection_state2str( c->c_conn_state ),
222 c->c_sasl_bind_in_progress ? "S" : "",
224 c->c_cdn ? c->c_cdn : SLAPD_ANONYMOUS,
239 val.bv_len = strlen( buf );
240 attr_merge( e, monitor_ad_desc, bv );
242 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
243 e->e_private = ( void * )mp;
244 mp->mp_info = &monitor_subsys[ SLAPD_MONITOR_CONN ];
245 mp->mp_children = NULL;
246 mp->mp_flags = MONITOR_F_SUB | MONITOR_F_VOLATILE;
254 monitor_subsys_conn_create(
255 struct monitorinfo *mi,
263 struct monitorentrypriv *mp;
265 assert( mi != NULL );
266 assert( e_parent != NULL );
267 assert( ep != NULL );
272 Entry *e, *e_tmp = NULL;
274 /* create all the children of e_parent */
275 for ( c = connection_first( &connindex );
277 c = connection_next( c, &connindex )) {
278 if ( conn_create( c, &e ) || e == NULL ) {
281 mp = ( struct monitorentrypriv * )e->e_private;
289 /* create exactly the required entry */
291 unsigned long connid;
293 rdn = dn_rdn( NULL, ndn );
294 value = rdn_attr_value( rdn );
295 connid = atol( value );
299 for ( c = connection_first( &connindex );
301 c = connection_next( c, &connindex )) {
302 if ( c->c_connid == connid ) {
303 if ( conn_create( c, ep ) || *ep == NULL ) {