1 /* operation.c - deal with operation subsystem */
3 * Copyright 1998-2003 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,
126 attr_merge_one( e, monitor_ad_desc, &bv, NULL );
128 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
129 e->e_private = ( void * )mp;
131 mp->mp_children = NULL;
132 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
133 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
134 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
136 if ( monitor_cache_add( mi, e ) ) {
138 LDAP_LOG( OPERATION, CRIT,
139 "monitor_subsys_ops_init: "
140 "unable to add entry 'cn=%s,%s'\n",
142 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
144 Debug( LDAP_DEBUG_ANY,
145 "monitor_subsys_ops_init: "
146 "unable to add entry 'cn=%s,%s'\n%s",
148 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
157 for ( i = SLAP_OP_LAST; i-- > 0; ) {
162 snprintf( buf, sizeof( buf ),
163 "dn: cn=%s,cn=%s,%s\n"
164 SLAPD_MONITOR_OBJECTCLASSES
168 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn.bv_val,
171 e = str2entry( buf );
174 LDAP_LOG( OPERATION, CRIT,
175 "monitor_subsys_ops_init: "
176 "unable to create entry 'cn=%s,cn=%s,%s'\n",
179 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
181 Debug( LDAP_DEBUG_ANY,
182 "monitor_subsys_ops_init: "
183 "unable to create entry 'cn=%s,cn=%s,%s'\n",
186 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
193 attr_merge_one( e, monitor_ad_desc, &bv, NULL );
195 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
196 e->e_private = ( void * )mp;
197 mp->mp_next = e_children;
198 mp->mp_children = NULL;
199 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
200 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
201 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
203 if ( monitor_cache_add( mi, e ) ) {
205 LDAP_LOG( OPERATION, CRIT,
206 "monitor_subsys_ops_init: "
207 "unable to add entry 'cn=%s,cn=%s,%s'\n",
210 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
212 Debug( LDAP_DEBUG_ANY,
213 "monitor_subsys_ops_init: "
214 "unable to add entry 'cn=%s,cn=%s,%s'\n",
217 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
225 mp = ( struct monitorentrypriv * )e_tmp->e_private;
226 mp->mp_children = e_children;
231 snprintf( buf, sizeof( buf ),
233 SLAPD_MONITOR_OBJECTCLASSES
236 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn.bv_val,
237 bv_completed.bv_val );
239 e = str2entry( buf );
242 LDAP_LOG( OPERATION, CRIT,
243 "monitor_subsys_ops_init: "
244 "unable to create entry 'cn=%s,%s'\n",
246 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
248 Debug( LDAP_DEBUG_ANY,
249 "monitor_subsys_ops_init: "
250 "unable to create entry 'cn=%s,%s'\n%s",
252 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
260 attr_merge_one( e, monitor_ad_desc, &bv, NULL );
262 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
263 e->e_private = ( void * )mp;
265 mp->mp_children = NULL;
266 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
267 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
268 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
270 if ( monitor_cache_add( mi, e ) ) {
272 LDAP_LOG( OPERATION, CRIT,
273 "monitor_subsys_ops_init: "
274 "unable to add entry 'cn=%s,%s'\n",
276 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
278 Debug( LDAP_DEBUG_ANY,
279 "monitor_subsys_ops_init: "
280 "unable to add entry 'cn=%s,%s'\n%s",
282 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
291 for ( i = SLAP_OP_LAST; i-- > 0; ) {
296 snprintf( buf, sizeof( buf ),
297 "dn: cn=%s,cn=%s,%s\n"
298 SLAPD_MONITOR_OBJECTCLASSES
302 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn.bv_val,
305 e = str2entry( buf );
308 LDAP_LOG( OPERATION, CRIT,
309 "monitor_subsys_ops_init: "
310 "unable to create entry 'cn=%s,cn=%s,%s'\n",
313 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
315 Debug( LDAP_DEBUG_ANY,
316 "monitor_subsys_ops_init: "
317 "unable to create entry 'cn=%s,cn=%s,%s'\n",
320 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
327 attr_merge_one( e, monitor_ad_desc, &bv, NULL );
329 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
330 e->e_private = ( void * )mp;
331 mp->mp_next = e_children;
332 mp->mp_children = NULL;
333 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
334 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
335 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
337 if ( monitor_cache_add( mi, e ) ) {
339 LDAP_LOG( OPERATION, CRIT,
340 "monitor_subsys_ops_init: "
341 "unable to add entry 'cn=%s,cn=%s,%s'\n",
344 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
346 Debug( LDAP_DEBUG_ANY,
347 "monitor_subsys_ops_init: "
348 "unable to add entry 'cn=%s,cn=%s,%s'\n",
351 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val );
359 mp = ( struct monitorentrypriv * )e_tmp->e_private;
360 mp->mp_children = e_children;
362 mp = ( struct monitorentrypriv * )e_op->e_private;
363 mp->mp_children = e_tmp;
365 monitor_cache_release( mi, e_op );
371 monitor_subsys_ops_update(
372 struct monitorinfo *mi,
384 if ( strncmp( dn, bv_initiated.bv_val,
385 bv_initiated.bv_len ) == 0 ) {
386 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
387 n = num_ops_initiated;
388 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
390 } else if ( strncmp( dn, bv_completed.bv_val,
391 bv_completed.bv_len ) == 0 ) {
392 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
393 n = num_ops_completed;
394 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
400 for (i = 0; i < SLAP_OP_LAST; i++ ) {
401 len = bv_op[ i ].bv_len;
403 if ( strncmp( dn, bv_op[ i ].bv_val, len ) == 0 ) {
408 if ( i == SLAP_OP_LAST ) {
414 if ( strncmp( dn, bv_initiated.bv_val,
415 bv_initiated.bv_len ) == 0 ) {
416 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
417 n = num_ops_initiated_[ i ];
418 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
420 } else if ( strncmp( dn, bv_completed.bv_val,
421 bv_completed.bv_len ) == 0 ) {
422 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
423 n = num_ops_completed_[ i ];
424 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
435 a = attr_find( e->e_attrs, monitor_ad_desc );
440 snprintf( buf, sizeof( buf ), "%ld", n );
441 free( a->a_vals[ 0 ].bv_val );
442 ber_str2bv( buf, 0, 1, a->a_vals );