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;
51 Entry *e, *e_tmp, *e_conn;
52 struct monitorentrypriv *mp;
54 struct berval val, *bv[2] = { &val, NULL };
58 mi = ( struct monitorinfo * )be->be_private;
60 if ( monitor_cache_get( mi,
61 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, &e_conn ) ) {
63 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
64 "monitor_subsys_conn_init: "
65 "unable to get entry '%s'\n",
66 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn->bv_val ));
68 Debug( LDAP_DEBUG_ANY,
69 "monitor_subsys_conn_init: "
70 "unable to get entry '%s'\n%s%s",
71 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn->bv_val,
82 snprintf( buf, sizeof( buf ),
85 "objectClass: LDAPsubEntry\n"
86 #ifdef SLAPD_MONITORSUBENTRY
87 "objectClass: monitorSubEntry\n"
88 #else /* !SLAPD_MONITORSUBENTRY */
89 "objectClass: extensibleObject\n"
90 #endif /* !SLAPD_MONITORSUBENTRY */
92 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn->bv_val );
97 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
98 "monitor_subsys_conn_init: "
99 "unable to create entry 'cn=Total,%s'\n",
100 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn->bv_val ));
102 Debug( LDAP_DEBUG_ANY,
103 "monitor_subsys_conn_init: "
104 "unable to create entry 'cn=Total,%s'\n%s%s",
105 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn->bv_val,
113 attr_merge( e, monitor_ad_desc, bv );
115 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
116 e->e_private = ( void * )mp;
118 mp->mp_children = NULL;
119 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_CONN];
120 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_CONN].mss_flags \
121 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
122 mp->mp_flags &= ~MONITOR_F_VOLATILE_CH;
124 if ( monitor_cache_add( mi, e ) ) {
126 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
127 "monitor_subsys_conn_init: "
128 "unable to add entry 'cn=Total,%s'\n",
129 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn->bv_val ));
131 Debug( LDAP_DEBUG_ANY,
132 "monitor_subsys_conn_init: "
133 "unable to add entry 'cn=Total,%s'\n%s%s",
134 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn->bv_val,
145 snprintf( buf, sizeof( buf ),
146 "dn: cn=Current,%s\n"
148 "objectClass: LDAPsubEntry\n"
149 #ifdef SLAPD_MONITORSUBENTRY
150 "objectClass: monitorSubEntry\n"
151 #else /* !SLAPD_MONITORSUBENTRY */
152 "objectClass: extensibleObject\n"
153 #endif /* !SLAPD_MONITORSUBENTRY */
155 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn->bv_val );
157 e = str2entry( buf );
160 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
161 "monitor_subsys_conn_init: "
162 "unable to create entry 'cn=Current,%s'\n",
163 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn->bv_val ));
165 Debug( LDAP_DEBUG_ANY,
166 "monitor_subsys_conn_init: "
167 "unable to create entry 'cn=Current,%s'\n%s%s",
168 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn->bv_val,
174 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
175 e->e_private = ( void * )mp;
177 mp->mp_children = NULL;
178 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_CONN];
179 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_CONN].mss_flags \
180 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
181 mp->mp_flags &= ~MONITOR_F_VOLATILE_CH;
183 if ( monitor_cache_add( mi, e ) ) {
185 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
186 "monitor_subsys_conn_init: "
187 "unable to add entry 'cn=Current,%s'\n",
188 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn->bv_val ));
190 Debug( LDAP_DEBUG_ANY,
191 "monitor_subsys_conn_init: "
192 "unable to add entry 'cn=Current,%s'\n%s%s",
193 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn->bv_val,
201 mp = ( struct monitorentrypriv * )e_conn->e_private;
202 mp->mp_children = e_tmp;
204 monitor_cache_release( mi, e_conn );
210 monitor_subsys_conn_update(
211 struct monitorinfo *mi,
220 if ( strncasecmp( e->e_ndn, "CN=TOTAL",
221 sizeof("CN=TOTAL")-1 ) == 0 ) {
222 n = connections_nextid();
224 } else if ( strncasecmp( e->e_ndn, "CN=CURRENT",
225 sizeof("CN=CURRENT")-1 ) == 0 ) {
229 for ( n = 0, c = connection_first( &connindex );
231 n++, c = connection_next( c, &connindex ) ) {
241 a = attr_find( e->e_attrs, monitor_ad_desc );
246 snprintf( buf, sizeof( buf ), "%ld", n );
247 ber_bvfree( a->a_vals[ 0 ] );
248 a->a_vals[ 0 ] = ber_bvstrdup( buf );
260 struct monitorentrypriv *mp;
266 struct berval val, *bv[2] = { &val, NULL };
271 assert( ep != NULL );
273 snprintf( buf, sizeof( buf ),
276 "objectClass: LDAPsubEntry\n"
277 #ifdef SLAPD_MONITORSUBENTRY
278 "objectClass: monitorSubEntry\n"
279 #else /* !SLAPD_MONITORSUBENTRY */
280 "objectClass: extensibleObject\n"
281 #endif /* !SLAPD_MONITORSUBENTRY */
283 c->c_connid, monitor_subsys[SLAPD_MONITOR_CONN].mss_dn->bv_val,
285 e = str2entry( buf );
289 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
290 "monitor_subsys_conn_create: "
291 "unable to create entry "
292 "'cn=%ld,%s' entry\n",
294 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn->bv_val ));
296 Debug( LDAP_DEBUG_ANY,
297 "monitor_subsys_conn_create: "
298 "unable to create entry "
299 "'cn=%ld,%s' entry\n",
301 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn->bv_val, 0 );
306 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
308 ltm = gmtime( &c->c_starttime );
309 strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
311 ltm = gmtime( &c->c_activitytime );
312 strftime( buf3, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
314 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
322 ": %s : %s : %s : %s",
324 (long) c->c_protocol,
325 c->c_n_ops_received, c->c_n_ops_executing,
326 c->c_n_ops_pending, c->c_n_ops_completed,
328 /* add low-level counters here */
329 c->c_n_get, c->c_n_read, c->c_n_write,
331 c->c_currentber ? "r" : "",
332 c->c_writewaiter ? "w" : "",
333 c->c_ops != NULL ? "x" : "",
334 c->c_pending_ops != NULL ? "p" : "",
335 connection_state2str( c->c_conn_state ),
336 c->c_sasl_bind_in_progress ? "S" : "",
338 c->c_cdn ? c->c_cdn : SLAPD_ANONYMOUS,
350 val.bv_len = strlen( buf );
351 attr_merge( e, monitor_ad_desc, bv );
353 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
354 e->e_private = ( void * )mp;
355 mp->mp_info = &monitor_subsys[ SLAPD_MONITOR_CONN ];
356 mp->mp_children = NULL;
357 mp->mp_flags = MONITOR_F_SUB | MONITOR_F_VOLATILE;
365 monitor_subsys_conn_create(
366 struct monitorinfo *mi,
374 struct monitorentrypriv *mp;
376 assert( mi != NULL );
377 assert( e_parent != NULL );
378 assert( ep != NULL );
383 Entry *e, *e_tmp = NULL;
385 /* create all the children of e_parent */
386 for ( c = connection_first( &connindex );
388 c = connection_next( c, &connindex )) {
389 if ( conn_create( c, &e ) || e == NULL ) {
393 mp = ( struct monitorentrypriv * )e->e_private;
404 unsigned long connid;
406 /* create exactly the required entry */
408 if ( dnExtractRdn( ndn, &rdn ) != LDAP_SUCCESS ) {
412 if ( rdn_attrs( rdn->bv_val, NULL, &values ) != LDAP_SUCCESS ) {
419 assert( values[ 0 ] );
421 connid = atol( values[ 0 ] );
423 ldap_value_free( values );
425 for ( c = connection_first( &connindex );
427 c = connection_next( c, &connindex )) {
428 if ( c->c_connid == connid ) {
429 if ( conn_create( c, ep ) || *ep == NULL ) {