1 /* operation.c - deal with operation subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2003 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by Pierangelo Masarati for inclusion
18 * in OpenLDAP Software.
20 /* This is an altered version */
22 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
24 * This work has beed deveolped for the OpenLDAP Foundation
25 * in the hope that it may be useful to the Open Source community,
26 * but WITHOUT ANY WARRANTY.
28 * Permission is granted to anyone to use this software for any purpose
29 * on any computer system, and to alter it and redistribute it, subject
30 * to the following restrictions:
32 * 1. The author and SysNet s.n.c. are not responsible for the consequences
33 * of use of this software, no matter how awful, even if they arise from
36 * 2. The origin of this software must not be misrepresented, either by
37 * explicit claim or by omission. Since few users ever read sources,
38 * credits should appear in the documentation.
40 * 3. Altered versions must be plainly marked as such, and must not be
41 * misrepresented as being the original software. Since few users
42 * ever read sources, credits should appear in the documentation.
43 * SysNet s.n.c. cannot be responsible for the consequences of the
46 * 4. This notice may not be removed or altered.
52 #include <ac/string.h>
55 #include "back-monitor.h"
69 BER_BVC( "Extended" ),
74 monitor_subsys_ops_init(
78 struct monitorinfo *mi;
80 Entry *e, *e_tmp, *e_op;
81 struct monitorentrypriv *mp;
82 char buf[ BACKMONITOR_BUFSIZE ];
87 mi = ( struct monitorinfo * )be->be_private;
89 if ( monitor_cache_get( mi,
90 &monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, &e_op ) ) {
92 LDAP_LOG( OPERATION, CRIT,
93 "monitor_subsys_ops_init: "
94 "unable to get entry '%s'\n",
95 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0, 0 );
97 Debug( LDAP_DEBUG_ANY,
98 "monitor_subsys_ops_init: "
99 "unable to get entry '%s'\n%s%s",
100 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
108 for ( i = SLAP_OP_LAST; i-- > 0; ) {
113 snprintf( buf, sizeof( buf ),
116 "structuralObjectClass: %s\n"
120 "createTimestamp: %s\n"
121 "modifyTimestamp: %s\n",
123 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn.bv_val,
124 mi->mi_oc_monitorOperation->soc_cname.bv_val,
125 mi->mi_oc_monitorOperation->soc_cname.bv_val,
127 mi->mi_ad_monitorOpInitiated->ad_cname.bv_val,
128 mi->mi_ad_monitorOpCompleted->ad_cname.bv_val,
129 mi->mi_startTime.bv_val,
130 mi->mi_startTime.bv_val );
132 e = str2entry( buf );
135 LDAP_LOG( OPERATION, CRIT,
136 "monitor_subsys_ops_init: "
137 "unable to create entry 'cn=%s,%s'\n",
139 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
141 Debug( LDAP_DEBUG_ANY,
142 "monitor_subsys_ops_init: "
143 "unable to create entry 'cn=%s,%s'\n",
145 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
150 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
151 e->e_private = ( void * )mp;
153 mp->mp_children = NULL;
154 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
155 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
156 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
158 if ( monitor_cache_add( mi, e ) ) {
160 LDAP_LOG( OPERATION, CRIT,
161 "monitor_subsys_ops_init: "
162 "unable to add entry 'cn=%s,%s'\n",
164 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
166 Debug( LDAP_DEBUG_ANY,
167 "monitor_subsys_ops_init: "
168 "unable to add entry 'cn=%s,%s'\n",
170 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
178 mp = ( struct monitorentrypriv * )e_op->e_private;
179 mp->mp_children = e_tmp;
181 monitor_cache_release( mi, e_op );
187 monitor_subsys_ops_update(
192 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
193 long nInitiated = -1, nCompleted = -1;
197 char buf[] = "+9223372036854775807L";
202 rdnvalue = e->e_dn + ( sizeof( "cn=" ) - 1 );
204 for (i = 0; i < SLAP_OP_LAST; i++ ) {
205 if ( strncmp( rdnvalue, bv_op[ i ].bv_val,
206 bv_op[ i ].bv_len ) == 0 ) {
207 nInitiated = num_ops_initiated_[ i ];
208 nCompleted = num_ops_completed_[ i ];
213 if ( i == SLAP_OP_LAST ) {
217 a = attr_find( e->e_attrs, mi->mi_ad_monitorOpInitiated );
218 assert ( a != NULL );
219 snprintf( buf, sizeof( buf ), "%ld", nInitiated );
220 free( a->a_vals[ 0 ].bv_val );
221 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );
223 a = attr_find( e->e_attrs, mi->mi_ad_monitorOpCompleted );
224 assert ( a != NULL );
225 snprintf( buf, sizeof( buf ), "%ld", nCompleted );
226 free( a->a_vals[ 0 ].bv_val );
227 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );