1 /* operation.c - deal with operation subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2003 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
25 #include <ac/string.h>
28 #include "back-monitor.h"
42 BER_BVC( "Extended" ),
47 monitor_subsys_ops_init(
51 struct monitorinfo *mi;
53 Entry *e, *e_tmp, *e_op;
54 struct monitorentrypriv *mp;
55 char buf[ BACKMONITOR_BUFSIZE ];
60 mi = ( struct monitorinfo * )be->be_private;
62 if ( monitor_cache_get( mi,
63 &monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, &e_op ) ) {
65 LDAP_LOG( OPERATION, CRIT,
66 "monitor_subsys_ops_init: "
67 "unable to get entry '%s'\n",
68 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0, 0 );
70 Debug( LDAP_DEBUG_ANY,
71 "monitor_subsys_ops_init: "
72 "unable to get entry '%s'\n%s%s",
73 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
81 for ( i = SLAP_OP_LAST; i-- > 0; ) {
86 snprintf( buf, sizeof( buf ),
89 "structuralObjectClass: %s\n"
93 "createTimestamp: %s\n"
94 "modifyTimestamp: %s\n",
96 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn.bv_val,
97 mi->mi_oc_monitorOperation->soc_cname.bv_val,
98 mi->mi_oc_monitorOperation->soc_cname.bv_val,
100 mi->mi_ad_monitorOpInitiated->ad_cname.bv_val,
101 mi->mi_ad_monitorOpCompleted->ad_cname.bv_val,
102 mi->mi_startTime.bv_val,
103 mi->mi_startTime.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",
118 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
123 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
124 e->e_private = ( void * )mp;
126 mp->mp_children = NULL;
127 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
128 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
129 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
131 if ( monitor_cache_add( mi, e ) ) {
133 LDAP_LOG( OPERATION, CRIT,
134 "monitor_subsys_ops_init: "
135 "unable to add entry 'cn=%s,%s'\n",
137 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
139 Debug( LDAP_DEBUG_ANY,
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 );
151 mp = ( struct monitorentrypriv * )e_op->e_private;
152 mp->mp_children = e_tmp;
154 monitor_cache_release( mi, e_op );
160 monitor_subsys_ops_update(
165 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
166 long nInitiated = -1, nCompleted = -1;
170 char buf[] = "+9223372036854775807L";
175 rdnvalue = e->e_dn + ( sizeof( "cn=" ) - 1 );
177 for (i = 0; i < SLAP_OP_LAST; i++ ) {
178 if ( strncmp( rdnvalue, bv_op[ i ].bv_val,
179 bv_op[ i ].bv_len ) == 0 ) {
180 nInitiated = num_ops_initiated_[ i ];
181 nCompleted = num_ops_completed_[ i ];
186 if ( i == SLAP_OP_LAST ) {
190 a = attr_find( e->e_attrs, mi->mi_ad_monitorOpInitiated );
191 assert ( a != NULL );
192 snprintf( buf, sizeof( buf ), "%ld", nInitiated );
193 free( a->a_vals[ 0 ].bv_val );
194 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );
196 a = attr_find( e->e_attrs, mi->mi_ad_monitorOpCompleted );
197 assert ( a != NULL );
198 snprintf( buf, sizeof( buf ), "%ld", nCompleted );
199 free( a->a_vals[ 0 ].bv_val );
200 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );