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.
37 #include <ac/string.h>
40 #include "back-monitor.h"
58 monitor_subsys_ops_init(
62 struct monitorinfo *mi;
64 Entry *e, *e_tmp, *e_op;
65 struct monitorentrypriv *mp;
66 char buf[ BACKMONITOR_BUFSIZE ];
71 mi = ( struct monitorinfo * )be->be_private;
73 if ( monitor_cache_get( mi,
74 &monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, &e_op ) ) {
76 LDAP_LOG( OPERATION, CRIT,
77 "monitor_subsys_ops_init: "
78 "unable to get entry '%s'\n",
79 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0, 0 );
81 Debug( LDAP_DEBUG_ANY,
82 "monitor_subsys_ops_init: "
83 "unable to get entry '%s'\n%s%s",
84 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
92 for ( i = SLAP_OP_LAST; i-- > 0; ) {
97 snprintf( buf, sizeof( buf ),
100 "structuralObjectClass: %s\n"
105 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn.bv_val,
106 mi->oc_monitorOperation->soc_cname.bv_val,
107 mi->oc_monitorOperation->soc_cname.bv_val,
109 mi->ad_monitorOpInitiated->ad_cname.bv_val,
110 mi->ad_monitorOpCompleted->ad_cname.bv_val );
112 e = str2entry( buf );
115 LDAP_LOG( OPERATION, CRIT,
116 "monitor_subsys_ops_init: "
117 "unable to create entry 'cn=%s,%s'\n",
119 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
121 Debug( LDAP_DEBUG_ANY,
122 "monitor_subsys_ops_init: "
123 "unable to create entry 'cn=%s,%s'\n",
125 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
130 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
131 e->e_private = ( void * )mp;
133 mp->mp_children = NULL;
134 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
135 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
136 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
138 if ( monitor_cache_add( mi, e ) ) {
140 LDAP_LOG( OPERATION, CRIT,
141 "monitor_subsys_ops_init: "
142 "unable to add entry 'cn=%s,%s'\n",
144 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
146 Debug( LDAP_DEBUG_ANY,
147 "monitor_subsys_ops_init: "
148 "unable to add entry 'cn=%s,%s'\n",
150 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
158 mp = ( struct monitorentrypriv * )e_op->e_private;
159 mp->mp_children = e_tmp;
161 monitor_cache_release( mi, e_op );
167 monitor_subsys_ops_update(
172 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
173 long nInitiated = -1, nCompleted = -1;
178 char buf[] = "+9223372036854775807L";
183 rdnvalue = e->e_dn + ( sizeof( "cn=" ) - 1 );
185 for (i = 0; i < SLAP_OP_LAST; i++ ) {
186 len = bv_op[ i ].bv_len;
188 if ( strncmp( rdnvalue, bv_op[ i ].bv_val, len ) == 0 ) {
189 nInitiated = num_ops_initiated_[ i ];
190 nCompleted = num_ops_completed_[ i ];
195 if ( i == SLAP_OP_LAST ) {
199 a = attr_find( e->e_attrs, mi->ad_monitorOpInitiated );
200 assert ( a != NULL );
201 snprintf( buf, sizeof( buf ), "%ld", nInitiated );
202 free( a->a_vals[ 0 ].bv_val );
203 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );
205 a = attr_find( e->e_attrs, mi->ad_monitorOpCompleted );
206 assert ( a != NULL );
207 snprintf( buf, sizeof( buf ), "%ld", nCompleted );
208 free( a->a_vals[ 0 ].bv_val );
209 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );