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;
53 struct berval *bv[2], val;
57 mi = ( struct monitorinfo * )be->be_private;
59 if ( monitor_cache_get( mi,
60 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, &e ) ) {
62 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
63 "monitor_subsys_conn_init: "
64 "unable to get entry '%s'\n",
65 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn ));
67 Debug( LDAP_DEBUG_ANY,
68 "monitor_subsys_conn_init: "
69 "unable to get entry '%s'\n%s%s",
70 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn,
79 monitor_cache_release( mi, e );
85 monitor_subsys_conn_update(
86 struct monitorinfo *mi,
92 int nconns, nwritewaiters, nreadwaiters;
95 struct berval *bv[2], val, **b = NULL;
104 nconns = nwritewaiters = nreadwaiters = 0;
105 for ( c = connection_first( &connindex );
107 c = connection_next( c, &connindex ), nconns++ ) {
108 if ( c->c_writewaiter ) {
111 if ( c->c_currentber != NULL ) {
118 snprintf( buf, sizeof( buf ), "readwaiters=%d", nreadwaiters );
120 if ( ( a = attr_find( e->e_attrs, monitor_ad_desc ) ) != NULL ) {
121 for ( b = a->a_vals; b[0] != NULL; b++ ) {
122 if ( strncmp( b[0]->bv_val, "readwaiters=",
123 sizeof( "readwaiters=" ) - 1 ) == 0 ) {
124 free( b[0]->bv_val );
125 b[0] = ber_bvstrdup( buf );
131 if ( b == NULL || b[0] == NULL ) {
133 val.bv_len = strlen( buf );
134 attr_merge( e, monitor_ad_desc, bv );
147 struct monitorentrypriv *mp;
153 struct berval *bv[2], val;
158 assert( ep != NULL );
160 snprintf( buf, sizeof( buf ),
163 "objectClass: LDAPsubEntry\n"
164 #ifdef SLAPD_MONITORSUBENTRY
165 "objectClass: monitorSubEntry\n"
166 #else /* !SLAPD_MONITORSUBENTRY */
167 "objectClass: extensibleObject\n"
168 #endif /* !SLAPD_MONITORSUBENTRY */
170 c->c_connid, monitor_subsys[SLAPD_MONITOR_CONN].mss_dn,
172 e = str2entry( buf );
176 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
177 "monitor_subsys_conn_create: "
178 "unable to create entry "
179 "'cn=%ld,%s' entry\n",
181 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn ));
183 Debug( LDAP_DEBUG_ANY,
184 "monitor_subsys_conn_create: "
185 "unable to create entry "
186 "'cn=%ld,%s' entry\n%s",
188 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn, "" );
193 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
195 ltm = gmtime( &c->c_starttime );
196 strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
198 ltm = gmtime( &c->c_activitytime );
199 strftime( buf3, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
201 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
209 ": %s : %s : %s : %s",
211 (long) c->c_protocol,
212 c->c_n_ops_received, c->c_n_ops_executing,
213 c->c_n_ops_pending, c->c_n_ops_completed,
215 /* add low-level counters here */
216 c->c_n_get, c->c_n_read, c->c_n_write,
218 c->c_currentber ? "r" : "",
219 c->c_writewaiter ? "w" : "",
220 c->c_ops != NULL ? "x" : "",
221 c->c_pending_ops != NULL ? "p" : "",
222 connection_state2str( c->c_conn_state ),
223 c->c_sasl_bind_in_progress ? "S" : "",
225 c->c_cdn ? c->c_cdn : SLAPD_ANONYMOUS,
240 val.bv_len = strlen( buf );
241 attr_merge( e, monitor_ad_desc, bv );
243 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
244 e->e_private = ( void * )mp;
245 mp->mp_info = &monitor_subsys[ SLAPD_MONITOR_CONN ];
246 mp->mp_children = NULL;
247 mp->mp_flags = MONITOR_F_SUB | MONITOR_F_VOLATILE;
255 monitor_subsys_conn_create(
256 struct monitorinfo *mi,
264 struct monitorentrypriv *mp;
266 assert( mi != NULL );
267 assert( e_parent != NULL );
268 assert( ep != NULL );
273 Entry *e, *e_tmp = NULL;
275 /* create all the children of e_parent */
276 for ( c = connection_first( &connindex );
278 c = connection_next( c, &connindex )) {
279 if ( conn_create( c, &e ) || e == NULL ) {
282 mp = ( struct monitorentrypriv * )e->e_private;
290 /* create exactly the required entry */
292 unsigned long connid;
294 rdn = dn_rdn( NULL, ndn );
295 value = rdn_attr_value( rdn );
296 connid = atol( value );
300 for ( c = connection_first( &connindex );
302 c = connection_next( c, &connindex )) {
303 if ( c->c_connid == connid ) {
304 if ( conn_create( c, ep ) || *ep == NULL ) {