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;
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,
114 attr_merge( e, monitor_ad_desc, bv );
116 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
117 e->e_private = ( void * )mp;
119 mp->mp_children = NULL;
120 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
121 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
122 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
124 if ( monitor_cache_add( mi, e ) ) {
126 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
127 "monitor_subsys_ops_init: "
128 "unable to add entry 'cn=Initiated,%s'\n",
129 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
131 Debug( LDAP_DEBUG_ANY,
132 "monitor_subsys_ops_init: "
133 "unable to add entry 'cn=Initiated,%s'\n%s%s",
134 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
145 snprintf( buf, sizeof( buf ),
146 "dn: cn=Completed,%s\n"
148 "objectClass: LDAPsubEntry\n"
149 #ifdef SLAPD_MONITORSUBENTRY
150 "objectClass: monitorSubEntry\n"
151 #else /* !SLAPD_MONITORSUBENTRY */
152 "objectClass: extensibleObject\n"
153 #endif /* !SLAPD_MONITORSUBENTRY */
155 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn.bv_val );
157 e = str2entry( buf );
160 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
161 "monitor_subsys_ops_init: "
162 "unable to create entry 'cn=Completed,%s'\n",
163 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
165 Debug( LDAP_DEBUG_ANY,
166 "monitor_subsys_ops_init: "
167 "unable to create entry 'cn=Completed,%s'\n%s%s",
168 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
176 attr_merge( e, monitor_ad_desc, bv );
178 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
179 e->e_private = ( void * )mp;
181 mp->mp_children = NULL;
182 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
183 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
184 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
186 if ( monitor_cache_add( mi, e ) ) {
188 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
189 "monitor_subsys_ops_init: "
190 "unable to add entry 'cn=Completed,%s'\n",
191 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val ));
193 Debug( LDAP_DEBUG_ANY,
194 "monitor_subsys_ops_init: "
195 "unable to add entry 'cn=Completed,%s'\n%s%s",
196 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
204 mp = ( struct monitorentrypriv * )e_op->e_private;
205 mp->mp_children = e_tmp;
207 monitor_cache_release( mi, e_op );
213 monitor_subsys_ops_update(
214 struct monitorinfo *mi,
223 if ( strncasecmp( e->e_ndn, "CN=INITIATED",
224 sizeof("CN=INITIATED")-1 ) == 0 ) {
225 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
226 n = num_ops_initiated;
227 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
229 } else if ( strncasecmp( e->e_ndn, "CN=COMPLETED",
230 sizeof("CN=COMPLETED")-1 ) == 0 ) {
231 ldap_pvt_thread_mutex_lock(&num_ops_mutex);
232 n = num_ops_completed;
233 ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
240 a = attr_find( e->e_attrs, monitor_ad_desc );
245 snprintf( buf, sizeof( buf ), "%ld", n );
246 free( a->a_vals[ 0 ].bv_val );
247 ber_str2bv( buf, 0, 1, a->a_vals );