1 /* operation.c - deal with operation 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"
43 bv_initiated = BER_BVC( "Initiated" ),
44 bv_completed = BER_BVC( "Completed" ),
59 monitor_subsys_ops_init(
63 struct monitorinfo *mi;
65 Entry *e, *e_tmp, *e_op, *e_children;
66 struct monitorentrypriv *mp;
73 mi = ( struct monitorinfo * )be->be_private;
75 if ( monitor_cache_get( mi,
76 &monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, &e_op ) ) {
78 LDAP_LOG( OPERATION, CRIT,
79 "monitor_subsys_ops_init: "
80 "unable to get entry '%s'\n",
81 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0, 0 );
83 Debug( LDAP_DEBUG_ANY,
84 "monitor_subsys_ops_init: "
85 "unable to get entry '%s'\n%s%s",
86 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
97 snprintf( buf, sizeof( buf ),
99 SLAPD_MONITOR_OBJECTCLASSES
102 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn.bv_val,
103 bv_initiated.bv_val );
105 e = str2entry( buf );
108 LDAP_LOG( OPERATION, CRIT,
109 "monitor_subsys_ops_init: "
110 "unable to create entry 'cn=%s,%s'\n",
112 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
114 Debug( LDAP_DEBUG_ANY,
115 "monitor_subsys_ops_init: "
116 "unable to create entry 'cn=%s,%s'\n%s",
118 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
127 attr_merge( e, monitor_ad_desc, bv );
129 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
130 e->e_private = ( void * )mp;
132 mp->mp_children = NULL;
133 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
134 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
135 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
137 if ( monitor_cache_add( mi, e ) ) {
139 LDAP_LOG( OPERATION, CRIT,
140 "monitor_subsys_ops_init: "
141 "unable to add entry 'cn=%s,%s'\n",
143 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
145 Debug( LDAP_DEBUG_ANY,
146 "monitor_subsys_ops_init: "
147 "unable to add entry 'cn=%s,%s'\n%s",
149 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
158 for ( i = SLAP_OP_LAST; i-- > 0; ) {
163 snprintf( buf, sizeof( buf ),
164 "dn: cn=%s,cn=%s,%s\n"
165 SLAPD_MONITOR_OBJECTCLASSES
169 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn.bv_val,
172 e = str2entry( buf );
175 LDAP_LOG( OPERATION, CRIT,
176 "monitor_subsys_ops_init: "
177 "unable to create entry 'cn=%s,cn=%s,%s'\n",
180 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
182 Debug( LDAP_DEBUG_ANY,
183 "monitor_subsys_ops_init: "
184 "unable to create entry 'cn=%s,cn=%s,%s'\n",
187 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
195 attr_merge( e, monitor_ad_desc, bv );
197 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
198 e->e_private = ( void * )mp;
199 mp->mp_next = e_children;
200 mp->mp_children = NULL;
201 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
202 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
203 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
205 if ( monitor_cache_add( mi, e ) ) {
207 LDAP_LOG( OPERATION, CRIT,
208 "monitor_subsys_ops_init: "
209 "unable to add entry 'cn=%s,cn=%s,%s'\n",
212 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
214 Debug( LDAP_DEBUG_ANY,
215 "monitor_subsys_ops_init: "
216 "unable to add entry 'cn=%s,cn=%s,%s'\n",
219 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
227 mp = ( struct monitorentrypriv * )e_tmp->e_private;
228 mp->mp_children = e_children;
233 snprintf( buf, sizeof( buf ),
235 SLAPD_MONITOR_OBJECTCLASSES
238 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn.bv_val,
239 bv_completed.bv_val );
241 e = str2entry( buf );
244 LDAP_LOG( OPERATION, CRIT,
245 "monitor_subsys_ops_init: "
246 "unable to create entry 'cn=%s,%s'\n",
248 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
250 Debug( LDAP_DEBUG_ANY,
251 "monitor_subsys_ops_init: "
252 "unable to create entry 'cn=%s,%s'\n%s",
254 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
262 attr_merge( e, monitor_ad_desc, bv );
264 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
265 e->e_private = ( void * )mp;
267 mp->mp_children = NULL;
268 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
269 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
270 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
272 if ( monitor_cache_add( mi, e ) ) {
274 LDAP_LOG( OPERATION, CRIT,
275 "monitor_subsys_ops_init: "
276 "unable to add entry 'cn=%s,%s'\n",
278 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
280 Debug( LDAP_DEBUG_ANY,
281 "monitor_subsys_ops_init: "
282 "unable to add entry 'cn=%s,%s'\n%s",
284 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
293 for ( i = SLAP_OP_LAST; i-- > 0; ) {
298 snprintf( buf, sizeof( buf ),
299 "dn: cn=%s,cn=%s,%s\n"
300 SLAPD_MONITOR_OBJECTCLASSES
304 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn.bv_val,
307 e = str2entry( buf );
310 LDAP_LOG( OPERATION, CRIT,
311 "monitor_subsys_ops_init: "
312 "unable to create entry 'cn=%s,cn=%s,%s'\n",
315 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
317 Debug( LDAP_DEBUG_ANY,
318 "monitor_subsys_ops_init: "
319 "unable to create entry 'cn=%s,cn=%s,%s'\n",
322 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
329 attr_merge( e, monitor_ad_desc, bv );
331 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
332 e->e_private = ( void * )mp;
333 mp->mp_next = e_children;
334 mp->mp_children = NULL;
335 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
336 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
337 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
339 if ( monitor_cache_add( mi, e ) ) {
341 LDAP_LOG( OPERATION, CRIT,
342 "monitor_subsys_ops_init: "
343 "unable to add entry 'cn=%s,cn=%s,%s'\n",
346 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
348 Debug( LDAP_DEBUG_ANY,
349 "monitor_subsys_ops_init: "
350 "unable to add entry 'cn=%s,cn=%s,%s'\n",
353 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
361 mp = ( struct monitorentrypriv * )e_tmp->e_private;
362 mp->mp_children = e_children;
364 mp = ( struct monitorentrypriv * )e_op->e_private;
365 mp->mp_children = e_tmp;
367 monitor_cache_release( mi, e_op );
373 monitor_subsys_ops_update(
374 struct monitorinfo *mi,
386 if ( strncmp( dn, bv_initiated.bv_val,
387 bv_initiated.bv_len ) == 0 ) {
388 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
389 n = num_ops_initiated;
390 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
392 } else if ( strncmp( dn, bv_completed.bv_val,
393 bv_completed.bv_len ) == 0 ) {
394 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
395 n = num_ops_completed;
396 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
402 for (i = 0; i < SLAP_OP_LAST; i++ ) {
403 len = bv_op[ i ].bv_len;
405 if ( strncmp( dn, bv_op[ i ].bv_val, len ) == 0 ) {
410 if ( i == SLAP_OP_LAST ) {
416 if ( strncmp( dn, bv_initiated.bv_val,
417 bv_initiated.bv_len ) == 0 ) {
418 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
419 n = num_ops_initiated_[ i ];
420 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
422 } else if ( strncmp( dn, bv_completed.bv_val,
423 bv_completed.bv_len ) == 0 ) {
424 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
425 n = num_ops_completed_[ i ];
426 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
437 a = attr_find( e->e_attrs, monitor_ad_desc );
442 snprintf( buf, sizeof( buf ), "%ld", n );
443 free( a->a_vals[ 0 ].bv_val );
444 ber_str2bv( buf, 0, 1, a->a_vals );