1 /* thread.c - deal with thread subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2006 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"
33 monitor_subsys_thread_update(
39 * initializes log subentry
42 monitor_subsys_thread_init(
49 Entry *e, **ep, *e_thread;
50 static char buf[ BACKMONITOR_BUFSIZE ];
52 ms->mss_update = monitor_subsys_thread_update;
54 mi = ( monitor_info_t * )be->be_private;
56 if ( monitor_cache_get( mi, &ms->mss_ndn, &e_thread ) ) {
57 Debug( LDAP_DEBUG_ANY,
58 "monitor_subsys_thread_init: unable to get entry \"%s\"\n",
64 mp = ( monitor_entry_t * )e_thread->e_private;
65 mp->mp_children = NULL;
66 ep = &mp->mp_children;
71 snprintf( buf, sizeof( buf ),
74 "structuralObjectClass: %s\n"
79 "createTimestamp: %s\n"
80 "modifyTimestamp: %s\n",
82 mi->mi_oc_monitoredObject->soc_cname.bv_val,
83 mi->mi_oc_monitoredObject->soc_cname.bv_val,
84 mi->mi_ad_monitoredInfo->ad_cname.bv_val,
86 mi->mi_creatorsName.bv_val,
87 mi->mi_creatorsName.bv_val,
88 mi->mi_startTime.bv_val,
89 mi->mi_startTime.bv_val );
93 Debug( LDAP_DEBUG_ANY,
94 "monitor_subsys_thread_init: "
95 "unable to create entry \"cn=Max,%s\"\n",
96 ms->mss_ndn.bv_val, 0, 0 );
100 mp = monitor_entrypriv_create();
104 e->e_private = ( void * )mp;
106 mp->mp_flags = ms->mss_flags \
107 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
109 if ( monitor_cache_add( mi, e ) ) {
110 Debug( LDAP_DEBUG_ANY,
111 "monitor_subsys_thread_init: "
112 "unable to add entry \"cn=Max,%s\"\n",
113 ms->mss_ndn.bv_val, 0, 0 );
123 snprintf( buf, sizeof( buf ),
124 "dn: cn=Backload,%s\n"
126 "structuralObjectClass: %s\n"
130 "modifiersName: %s\n"
131 "createTimestamp: %s\n"
132 "modifyTimestamp: %s\n",
134 mi->mi_oc_monitoredObject->soc_cname.bv_val,
135 mi->mi_oc_monitoredObject->soc_cname.bv_val,
136 mi->mi_ad_monitoredInfo->ad_cname.bv_val,
137 mi->mi_creatorsName.bv_val,
138 mi->mi_creatorsName.bv_val,
139 mi->mi_startTime.bv_val,
140 mi->mi_startTime.bv_val );
142 e = str2entry( buf );
144 Debug( LDAP_DEBUG_ANY,
145 "monitor_subsys_thread_init: "
146 "unable to create entry \"cn=Backload,%s\"\n",
147 ms->mss_ndn.bv_val, 0, 0 );
151 mp = monitor_entrypriv_create();
155 e->e_private = ( void * )mp;
157 mp->mp_flags = ms->mss_flags \
158 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
160 if ( monitor_cache_add( mi, e ) ) {
161 Debug( LDAP_DEBUG_ANY,
162 "monitor_subsys_thread_init: "
163 "unable to add entry \"cn=Backload,%s\"\n",
164 ms->mss_ndn.bv_val, 0, 0 );
174 snprintf( buf, sizeof( buf ),
175 "dn: cn=Runqueue,%s\n"
177 "structuralObjectClass: %s\n"
181 "modifiersName: %s\n"
182 "createTimestamp: %s\n"
183 "modifyTimestamp: %s\n",
185 mi->mi_oc_monitoredObject->soc_cname.bv_val,
186 mi->mi_oc_monitoredObject->soc_cname.bv_val,
187 mi->mi_ad_monitoredInfo->ad_cname.bv_val,
188 mi->mi_creatorsName.bv_val,
189 mi->mi_creatorsName.bv_val,
190 mi->mi_startTime.bv_val,
191 mi->mi_startTime.bv_val );
193 e = str2entry( buf );
195 Debug( LDAP_DEBUG_ANY,
196 "monitor_subsys_thread_init: "
197 "unable to create entry \"cn=Runqueue,%s\"\n",
198 ms->mss_ndn.bv_val, 0, 0 );
202 mp = monitor_entrypriv_create();
206 e->e_private = ( void * )mp;
208 mp->mp_flags = ms->mss_flags \
209 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
211 if ( monitor_cache_add( mi, e ) ) {
212 Debug( LDAP_DEBUG_ANY,
213 "monitor_subsys_thread_init: "
214 "unable to add entry \"cn=Runqueue,%s\"\n",
215 ms->mss_ndn.bv_val, 0, 0 );
222 monitor_cache_release( mi, e_thread );
228 monitor_subsys_thread_update(
233 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
235 char buf[ BACKMONITOR_BUFSIZE ];
236 static struct berval backload_bv = BER_BVC( "cn=backload" );
237 static struct berval runqueue_bv = BER_BVC( "cn=runqueue" );
238 struct berval rdn, bv;
243 assert( mi != NULL );
245 dnRdn( &e->e_nname, &rdn );
246 if ( dn_match( &rdn, &backload_bv ) ) {
249 } else if ( dn_match( &rdn, &runqueue_bv ) ) {
253 return SLAP_CB_CONTINUE;
256 a = attr_find( e->e_attrs, mi->mi_ad_monitoredInfo );
258 return rs->sr_err = LDAP_OTHER;
263 snprintf( buf, sizeof( buf ), "%d",
264 ldap_pvt_thread_pool_backload( &connection_pool ) );
266 if ( len > a->a_vals[ 0 ].bv_len ) {
267 a->a_vals[ 0 ].bv_val = ber_memrealloc( a->a_vals[ 0 ].bv_val, len + 1 );
269 a->a_vals[ 0 ].bv_len = len;
270 AC_MEMCPY( a->a_vals[ 0 ].bv_val, buf, len + 1 );
274 for ( i = 0; !BER_BVISNULL( a->a_vals + i ); i++) {
275 ch_free( a->a_vals[i].bv_val );
276 BER_BVZERO( a->a_vals + i );
279 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
280 LDAP_STAILQ_FOREACH( re, &slapd_rq.run_list, rnext ) {
281 bv.bv_len = snprintf( buf, sizeof( buf ), "%s(%s)",
282 re->tname, re->tspec );
283 value_add_one( &a->a_vals, &bv );
285 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
289 /* FIXME: touch modifyTimestamp? */
291 return SLAP_CB_CONTINUE;