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"
42 monitor_subsys_ops_init(
46 struct monitorinfo *mi;
48 Entry *e, *e_tmp, *e_op;
49 struct monitorentrypriv *mp;
55 mi = ( struct monitorinfo * )be->be_private;
57 if ( monitor_cache_get( mi,
58 &monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, &e_op ) ) {
60 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
61 "monitor_subsys_ops_init: "
62 "unable to get entry '%s'\n",
63 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
65 Debug( LDAP_DEBUG_ANY,
66 "monitor_subsys_ops_init: "
67 "unable to get entry '%s'\n%s%s",
68 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
79 snprintf( buf, sizeof( buf ),
80 "dn: cn=Initiated,%s\n"
81 SLAPD_MONITOR_OBJECTCLASSES
83 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn.bv_val );
88 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
89 "monitor_subsys_ops_init: "
90 "unable to create entry 'cn=Initiated,%s'\n",
91 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
93 Debug( LDAP_DEBUG_ANY,
94 "monitor_subsys_ops_init: "
95 "unable to create entry 'cn=Initiated,%s'\n%s%s",
96 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
105 attr_merge( e, monitor_ad_desc, bv );
107 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
108 e->e_private = ( void * )mp;
110 mp->mp_children = NULL;
111 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
112 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
113 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
115 if ( monitor_cache_add( mi, e ) ) {
117 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
118 "monitor_subsys_ops_init: "
119 "unable to add entry 'cn=Initiated,%s'\n",
120 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
122 Debug( LDAP_DEBUG_ANY,
123 "monitor_subsys_ops_init: "
124 "unable to add entry 'cn=Initiated,%s'\n%s%s",
125 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
136 snprintf( buf, sizeof( buf ),
137 "dn: cn=Completed,%s\n"
138 SLAPD_MONITOR_OBJECTCLASSES
140 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn.bv_val );
142 e = str2entry( buf );
145 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
146 "monitor_subsys_ops_init: "
147 "unable to create entry 'cn=Completed,%s'\n",
148 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
150 Debug( LDAP_DEBUG_ANY,
151 "monitor_subsys_ops_init: "
152 "unable to create entry 'cn=Completed,%s'\n%s%s",
153 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
161 attr_merge( e, monitor_ad_desc, bv );
163 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
164 e->e_private = ( void * )mp;
166 mp->mp_children = NULL;
167 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
168 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
169 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
171 if ( monitor_cache_add( mi, e ) ) {
173 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
174 "monitor_subsys_ops_init: "
175 "unable to add entry 'cn=Completed,%s'\n",
176 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
178 Debug( LDAP_DEBUG_ANY,
179 "monitor_subsys_ops_init: "
180 "unable to add entry 'cn=Completed,%s'\n%s%s",
181 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
189 mp = ( struct monitorentrypriv * )e_op->e_private;
190 mp->mp_children = e_tmp;
192 monitor_cache_release( mi, e_op );
198 monitor_subsys_ops_update(
199 struct monitorinfo *mi,
208 if ( strncasecmp( e->e_ndn, "CN=INITIATED",
209 sizeof("CN=INITIATED")-1 ) == 0 ) {
210 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
211 n = num_ops_initiated;
212 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
214 } else if ( strncasecmp( e->e_ndn, "CN=COMPLETED",
215 sizeof("CN=COMPLETED")-1 ) == 0 ) {
216 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
217 n = num_ops_completed;
218 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
225 a = attr_find( e->e_attrs, monitor_ad_desc );
230 snprintf( buf, sizeof( buf ), "%ld", n );
231 free( a->a_vals[ 0 ].bv_val );
232 ber_str2bv( buf, 0, 1, a->a_vals );