1 /* operation.c - deal with operation subsystem */
3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
8 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
12 * This work has beed deveolped for the OpenLDAP Foundation
13 * in the hope that it may be useful to the Open Source community,
14 * but WITHOUT ANY WARRANTY.
16 * Permission is granted to anyone to use this software for any purpose
17 * on any computer system, and to alter it and redistribute it, subject
18 * to the following restrictions:
20 * 1. The author and SysNet s.n.c. are not responsible for the consequences
21 * of use of this software, no matter how awful, even if they arise from
24 * 2. The origin of this software must not be misrepresented, either by
25 * explicit claim or by omission. Since few users ever read sources,
26 * credits should appear in the documentation.
28 * 3. Altered versions must be plainly marked as such, and must not be
29 * misrepresented as being the original software. Since few users
30 * ever read sources, credits should appear in the documentation.
31 * SysNet s.n.c. cannot be responsible for the consequences of the
34 * 4. This notice may not be removed or altered.
42 #include "back-monitor.h"
45 monitor_subsys_ops_init(
49 struct monitorinfo *mi;
51 Entry *e, *e_tmp, *e_op;
52 struct monitorentrypriv *mp;
54 struct berval val, *bv[2] = { &val, NULL };
58 mi = ( struct monitorinfo * )be->be_private;
60 if ( monitor_cache_get( mi,
61 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, &e_op ) ) {
63 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
64 "monitor_subsys_ops_init: "
65 "unable to get entry '%s'\n",
66 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn->bv_val ));
68 Debug( LDAP_DEBUG_ANY,
69 "monitor_subsys_ops_init: "
70 "unable to get entry '%s'\n%s%s",
71 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn->bv_val,
82 snprintf( buf, sizeof( buf ),
83 "dn: cn=Initiated,%s\n"
85 "objectClass: LDAPsubEntry\n"
86 #ifdef SLAPD_MONITORSUBENTRY
87 "objectClass: monitorSubEntry\n"
88 #else /* !SLAPD_MONITORSUBENTRY */
89 "objectClass: extensibleObject\n"
90 #endif /* !SLAPD_MONITORSUBENTRY */
92 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn->bv_val );
97 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
98 "monitor_subsys_ops_init: "
99 "unable to create entry 'cn=Initiated,%s'\n",
100 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn->bv_val ));
102 Debug( LDAP_DEBUG_ANY,
103 "monitor_subsys_ops_init: "
104 "unable to create entry 'cn=Initiated,%s'\n%s%s",
105 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn->bv_val,
113 attr_merge( e, monitor_ad_desc, bv );
115 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
116 e->e_private = ( void * )mp;
118 mp->mp_children = NULL;
119 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
120 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
121 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
123 if ( monitor_cache_add( mi, e ) ) {
125 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
126 "monitor_subsys_ops_init: "
127 "unable to add entry 'cn=Initiated,%s'\n",
128 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn->bv_val ));
130 Debug( LDAP_DEBUG_ANY,
131 "monitor_subsys_ops_init: "
132 "unable to add entry 'cn=Initiated,%s'\n%s%s",
133 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn->bv_val,
144 snprintf( buf, sizeof( buf ),
145 "dn: cn=Completed,%s\n"
147 "objectClass: LDAPsubEntry\n"
148 #ifdef SLAPD_MONITORSUBENTRY
149 "objectClass: monitorSubEntry\n"
150 #else /* !SLAPD_MONITORSUBENTRY */
151 "objectClass: extensibleObject\n"
152 #endif /* !SLAPD_MONITORSUBENTRY */
154 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn->bv_val );
156 e = str2entry( buf );
159 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
160 "monitor_subsys_ops_init: "
161 "unable to create entry 'cn=Completed,%s'\n",
162 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn->bv_val ));
164 Debug( LDAP_DEBUG_ANY,
165 "monitor_subsys_ops_init: "
166 "unable to create entry 'cn=Completed,%s'\n%s%s",
167 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn->bv_val,
175 attr_merge( e, monitor_ad_desc, bv );
177 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
178 e->e_private = ( void * )mp;
180 mp->mp_children = NULL;
181 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
182 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
183 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
185 if ( monitor_cache_add( mi, e ) ) {
187 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
188 "monitor_subsys_ops_init: "
189 "unable to add entry 'cn=Completed,%s'\n",
190 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn->bv_val ));
192 Debug( LDAP_DEBUG_ANY,
193 "monitor_subsys_ops_init: "
194 "unable to add entry 'cn=Completed,%s'\n%s%s",
195 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn->bv_val,
203 mp = ( struct monitorentrypriv * )e_op->e_private;
204 mp->mp_children = e_tmp;
206 monitor_cache_release( mi, e_op );
212 monitor_subsys_ops_update(
213 struct monitorinfo *mi,
222 if ( strncasecmp( e->e_ndn, "CN=INITIATED",
223 sizeof("CN=INITIATED")-1 ) == 0 ) {
224 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
225 n = num_ops_initiated;
226 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
228 } else if ( strncasecmp( e->e_ndn, "CN=COMPLETED",
229 sizeof("CN=COMPLETED")-1 ) == 0 ) {
230 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
231 n = num_ops_completed;
232 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
239 a = attr_find( e->e_attrs, monitor_ad_desc );
244 snprintf( buf, sizeof( buf ), "%ld", n );
245 ber_bvfree( a->a_vals[ 0 ] );
246 a->a_vals[ 0 ] = ber_bvstrdup( buf );