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 ),
81 SLAPD_MONITOR_OBJECTCLASSES
83 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val );
88 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
89 "monitor_subsys_conn_init: "
90 "unable to create entry 'cn=Total,%s'\n",
91 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
93 Debug( LDAP_DEBUG_ANY,
94 "monitor_subsys_conn_init: "
95 "unable to create entry 'cn=Total,%s'\n%s%s",
96 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val,
105 attr_merge( e, monitor_ad_desc, bv );
107 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
108 e->e_private = ( void * )mp;
110 mp->mp_children = NULL;
111 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_CONN];
112 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_CONN].mss_flags \
113 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
114 mp->mp_flags &= ~MONITOR_F_VOLATILE_CH;
116 if ( monitor_cache_add( mi, e ) ) {
118 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
119 "monitor_subsys_conn_init: "
120 "unable to add entry 'cn=Total,%s'\n",
121 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
123 Debug( LDAP_DEBUG_ANY,
124 "monitor_subsys_conn_init: "
125 "unable to add entry 'cn=Total,%s'\n%s%s",
126 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val,
137 snprintf( buf, sizeof( buf ),
138 "dn: cn=Current,%s\n"
139 SLAPD_MONITOR_OBJECTCLASSES
141 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val );
143 e = str2entry( buf );
146 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
147 "monitor_subsys_conn_init: "
148 "unable to create entry 'cn=Current,%s'\n",
149 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
151 Debug( LDAP_DEBUG_ANY,
152 "monitor_subsys_conn_init: "
153 "unable to create entry 'cn=Current,%s'\n%s%s",
154 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val,
160 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
161 e->e_private = ( void * )mp;
163 mp->mp_children = NULL;
164 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_CONN];
165 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_CONN].mss_flags \
166 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
167 mp->mp_flags &= ~MONITOR_F_VOLATILE_CH;
169 if ( monitor_cache_add( mi, e ) ) {
171 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
172 "monitor_subsys_conn_init: "
173 "unable to add entry 'cn=Current,%s'\n",
174 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val ));
176 Debug( LDAP_DEBUG_ANY,
177 "monitor_subsys_conn_init: "
178 "unable to add entry 'cn=Current,%s'\n%s%s",
179 monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn.bv_val,
187 mp = ( struct monitorentrypriv * )e_conn->e_private;
188 mp->mp_children = e_tmp;
190 monitor_cache_release( mi, e_conn );
196 monitor_subsys_conn_update(
197 struct monitorinfo *mi,
206 if ( strncasecmp( e->e_ndn, "CN=TOTAL",
207 sizeof("CN=TOTAL")-1 ) == 0 ) {
208 n = connections_nextid();
210 } else if ( strncasecmp( e->e_ndn, "CN=CURRENT",
211 sizeof("CN=CURRENT")-1 ) == 0 ) {
215 for ( n = 0, c = connection_first( &connindex );
217 n++, c = connection_next( c, &connindex ) ) {
227 a = attr_find( e->e_attrs, monitor_ad_desc );
232 snprintf( buf, sizeof( buf ), "%ld", n );
233 free( a->a_vals[ 0 ].bv_val );
234 ber_str2bv( buf, 0, 1, a->a_vals );
246 struct monitorentrypriv *mp;
257 assert( ep != NULL );
259 snprintf( buf, sizeof( buf ),
260 "dn: cn=Connection %ld,%s\n"
261 SLAPD_MONITOR_OBJECTCLASSES
262 "cn: Connection %ld\n",
263 c->c_connid, monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val,
265 e = str2entry( buf );
269 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
270 "monitor_subsys_conn_create: "
271 "unable to create entry "
272 "'cn=Connection %ld,%s' entry\n",
274 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val ));
276 Debug( LDAP_DEBUG_ANY,
277 "monitor_subsys_conn_create: "
278 "unable to create entry "
279 "'cn=Connection %ld,%s' entry\n",
281 monitor_subsys[SLAPD_MONITOR_CONN].mss_dn.bv_val, 0 );
286 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
288 ltm = gmtime( &c->c_starttime );
289 strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
291 ltm = gmtime( &c->c_activitytime );
292 strftime( buf3, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
294 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
302 ": %s : %s : %s : %s",
304 (long) c->c_protocol,
305 c->c_n_ops_received, c->c_n_ops_executing,
306 c->c_n_ops_pending, c->c_n_ops_completed,
308 /* add low-level counters here */
309 c->c_n_get, c->c_n_read, c->c_n_write,
311 c->c_currentber ? "r" : "",
312 c->c_writewaiter ? "w" : "",
313 LDAP_STAILQ_EMPTY( &c->c_ops ) ? "" : "x",
314 LDAP_STAILQ_EMPTY( &c->c_pending_ops ) ? "" : "p",
315 connection_state2str( c->c_conn_state ),
316 c->c_sasl_bind_in_progress ? "S" : "",
318 c->c_cdn.bv_len ? c->c_cdn.bv_val : SLAPD_ANONYMOUS,
320 c->c_listener_url.bv_val,
321 c->c_peer_domain.bv_val,
322 c->c_peer_name.bv_val,
323 c->c_sock_name.bv_val,
331 bv[0].bv_len = strlen( buf );
332 attr_merge( e, monitor_ad_desc, bv );
334 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
335 e->e_private = ( void * )mp;
336 mp->mp_info = &monitor_subsys[ SLAPD_MONITOR_CONN ];
337 mp->mp_children = NULL;
338 mp->mp_flags = MONITOR_F_SUB | MONITOR_F_VOLATILE;
346 monitor_subsys_conn_create(
347 struct monitorinfo *mi,
355 struct monitorentrypriv *mp;
357 assert( mi != NULL );
358 assert( e_parent != NULL );
359 assert( ep != NULL );
364 Entry *e, *e_tmp = NULL;
366 /* create all the children of e_parent */
367 for ( c = connection_first( &connindex );
369 c = connection_next( c, &connindex )) {
370 if ( conn_create( c, &e ) || e == NULL ) {
374 mp = ( struct monitorentrypriv * )e->e_private;
383 LDAPRDN *values = NULL;
384 const char *text = NULL;
385 unsigned long connid;
387 /* create exactly the required entry */
389 if ( ldap_str2rdn( ndn->bv_val, &values, (char **)&text,
390 LDAP_DN_FORMAT_LDAP ) )
396 assert( values[ 0 ][ 0 ] );
398 connid = atol( values[ 0 ][ 0 ]->la_value.bv_val );
400 ldap_rdnfree( values );
402 for ( c = connection_first( &connindex );
404 c = connection_next( c, &connindex )) {
405 if ( c->c_connid == connid ) {
406 if ( conn_create( c, ep ) || *ep == NULL ) {