1 /* conn.c - deal with connection subsystem */
3 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
9 * This work has beed deveolped for the OpenLDAP Foundation
10 * in the hope that it may be useful to the Open Source community,
11 * but WITHOUT ANY WARRANTY.
13 * Permission is granted to anyone to use this software for any purpose
14 * on any computer system, and to alter it and redistribute it, subject
15 * to the following restrictions:
17 * 1. The author and SysNet s.n.c. are not responsible for the consequences
18 * of use of this software, no matter how awful, even if they arise from
21 * 2. The origin of this software must not be misrepresented, either by
22 * explicit claim or by omission. Since few users ever read sources,
23 * credits should appear in the documentation.
25 * 3. Altered versions must be plainly marked as such, and must not be
26 * misrepresented as being the original software. Since few users
27 * ever read sources, credits should appear in the documentation.
28 * SysNet s.n.c. cannot be responsible for the consequences of the
31 * 4. This notice may not be removed or altered.
39 #include "back-monitor.h"
42 monitor_subsys_conn_init(
46 struct monitorinfo *mi;
48 Entry *e, *e_tmp, *e_conn;
49 struct monitorentrypriv *mp;
55 mi = ( struct monitorinfo * )be->be_private;
57 if ( monitor_cache_get( mi,
58 &monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, &e_conn ) ) {
60 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
61 "monitor_subsys_conn_init: "
62 "unable to get entry '%s'\n",
63 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
65 Debug( LDAP_DEBUG_ANY,
66 "monitor_subsys_conn_init: "
67 "unable to get entry '%s'\n%s%s",
68 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val,
79 snprintf( buf, sizeof( buf ),
82 "objectClass: LDAPsubEntry\n"
83 #ifdef SLAPD_MONITORSUBENTRY
84 "objectClass: monitor\n"
85 #else /* !SLAPD_MONITORSUBENTRY */
86 "objectClass: extensibleObject\n"
87 #endif /* !SLAPD_MONITORSUBENTRY */
89 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val );
94 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
95 "monitor_subsys_conn_init: "
96 "unable to create entry 'cn=Total,%s'\n",
97 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
99 Debug( LDAP_DEBUG_ANY,
100 "monitor_subsys_conn_init: "
101 "unable to create entry 'cn=Total,%s'\n%s%s",
102 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val,
111 attr_merge( e, monitor_ad_desc, bv );
113 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
114 e->e_private = ( void * )mp;
116 mp->mp_children = NULL;
117 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_CONN];
118 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_CONN].mss_flags \
119 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
120 mp->mp_flags &= ~MONITOR_F_VOLATILE_CH;
122 if ( monitor_cache_add( mi, e ) ) {
124 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
125 "monitor_subsys_conn_init: "
126 "unable to add entry 'cn=Total,%s'\n",
127 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
129 Debug( LDAP_DEBUG_ANY,
130 "monitor_subsys_conn_init: "
131 "unable to add entry 'cn=Total,%s'\n%s%s",
132 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val,
143 snprintf( buf, sizeof( buf ),
144 "dn: cn=Current,%s\n"
146 "objectClass: LDAPsubEntry\n"
147 #ifdef SLAPD_MONITORSUBENTRY
148 "objectClass: monitorSubEntry\n"
149 #else /* !SLAPD_MONITORSUBENTRY */
150 "objectClass: extensibleObject\n"
151 #endif /* !SLAPD_MONITORSUBENTRY */
153 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val );
155 e = str2entry( buf );
158 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
159 "monitor_subsys_conn_init: "
160 "unable to create entry 'cn=Current,%s'\n",
161 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
163 Debug( LDAP_DEBUG_ANY,
164 "monitor_subsys_conn_init: "
165 "unable to create entry 'cn=Current,%s'\n%s%s",
166 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val,
172 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
173 e->e_private = ( void * )mp;
175 mp->mp_children = NULL;
176 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_CONN];
177 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_CONN].mss_flags \
178 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
179 mp->mp_flags &= ~MONITOR_F_VOLATILE_CH;
181 if ( monitor_cache_add( mi, e ) ) {
183 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
184 "monitor_subsys_conn_init: "
185 "unable to add entry 'cn=Current,%s'\n",
186 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
188 Debug( LDAP_DEBUG_ANY,
189 "monitor_subsys_conn_init: "
190 "unable to add entry 'cn=Current,%s'\n%s%s",
191 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val,
199 mp = ( struct monitorentrypriv * )e_conn->e_private;
200 mp->mp_children = e_tmp;
202 monitor_cache_release( mi, e_conn );
208 monitor_subsys_conn_update(
209 struct monitorinfo *mi,
218 if ( strncasecmp( e->e_ndn, "CN=TOTAL",
219 sizeof("CN=TOTAL")-1 ) == 0 ) {
220 n = connections_nextid();
222 } else if ( strncasecmp( e->e_ndn, "CN=CURRENT",
223 sizeof("CN=CURRENT")-1 ) == 0 ) {
227 for ( n = 0, c = connection_first( &connindex );
229 n++, c = connection_next( c, &connindex ) ) {
239 a = attr_find( e->e_attrs, monitor_ad_desc );
244 snprintf( buf, sizeof( buf ), "%ld", n );
245 free( a->a_vals[ 0 ].bv_val );
246 ber_str2bv( buf, 0, 1, a->a_vals );
258 struct monitorentrypriv *mp;
269 assert( ep != NULL );
271 snprintf( buf, sizeof( buf ),
274 "objectClass: LDAPsubEntry\n"
275 #ifdef SLAPD_MONITORSUBENTRY
276 "objectClass: monitorSubEntry\n"
277 #else /* !SLAPD_MONITORSUBENTRY */
278 "objectClass: extensibleObject\n"
279 #endif /* !SLAPD_MONITORSUBENTRY */
281 c->c_connid, monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val,
283 e = str2entry( buf );
287 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
288 "monitor_subsys_conn_create: "
289 "unable to create entry "
290 "'cn=%ld,%s' entry\n",
292 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val ));
294 Debug( LDAP_DEBUG_ANY,
295 "monitor_subsys_conn_create: "
296 "unable to create entry "
297 "'cn=%ld,%s' entry\n",
299 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val, 0 );
304 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
306 ltm = gmtime( &c->c_starttime );
307 strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
309 ltm = gmtime( &c->c_activitytime );
310 strftime( buf3, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
312 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
320 ": %s : %s : %s : %s",
322 (long) c->c_protocol,
323 c->c_n_ops_received, c->c_n_ops_executing,
324 c->c_n_ops_pending, c->c_n_ops_completed,
326 /* add low-level counters here */
327 c->c_n_get, c->c_n_read, c->c_n_write,
329 c->c_currentber ? "r" : "",
330 c->c_writewaiter ? "w" : "",
331 LDAP_STAILQ_EMPTY( &c->c_ops ) ? "" : "x",
332 LDAP_STAILQ_EMPTY( &c->c_pending_ops ) ? "" : "p",
333 connection_state2str( c->c_conn_state ),
334 c->c_sasl_bind_in_progress ? "S" : "",
336 c->c_cdn.bv_len ? c->c_cdn.bv_val : SLAPD_ANONYMOUS,
349 bv[0].bv_len = strlen( buf );
350 attr_merge( e, monitor_ad_desc, bv );
352 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
353 e->e_private = ( void * )mp;
354 mp->mp_info = &monitor_subsys[ SLAPD_MONITOR_CONN ];
355 mp->mp_children = NULL;
356 mp->mp_flags = MONITOR_F_SUB | MONITOR_F_VOLATILE;
364 monitor_subsys_conn_create(
365 struct monitorinfo *mi,
373 struct monitorentrypriv *mp;
375 assert( mi != NULL );
376 assert( e_parent != NULL );
377 assert( ep != NULL );
382 Entry *e, *e_tmp = NULL;
384 /* create all the children of e_parent */
385 for ( c = connection_first( &connindex );
387 c = connection_next( c, &connindex )) {
388 if ( conn_create( c, &e ) || e == NULL ) {
392 mp = ( struct monitorentrypriv * )e->e_private;
401 LDAPRDN *values = NULL;
402 const char *text = NULL;
403 unsigned long connid;
405 /* create exactly the required entry */
407 if ( ldap_str2rdn( ndn->bv_val, &values, (char **)&text,
408 LDAP_DN_FORMAT_LDAP ) )
414 assert( values[ 0 ][ 0 ] );
416 connid = atol( values[ 0 ][ 0 ]->la_value.bv_val );
418 ldap_rdnfree( values );
420 for ( c = connection_first( &connindex );
422 c = connection_next( c, &connindex )) {
423 if ( c->c_connid == connid ) {
424 if ( conn_create( c, ep ) || *ep == NULL ) {