1 /* thread.c - deal with thread subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2005 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 * * initializes log subentry
36 monitor_subsys_thread_init(
43 Entry *e, **ep, *e_thread;
44 static char buf[ BACKMONITOR_BUFSIZE ];
46 mi = ( monitor_info_t * )be->be_private;
48 if ( monitor_cache_get( mi, &ms->mss_ndn, &e_thread ) ) {
49 Debug( LDAP_DEBUG_ANY,
50 "monitor_subsys_thread_init: unable to get entry \"%s\"\n",
56 mp = ( monitor_entry_t * )e_thread->e_private;
57 mp->mp_children = NULL;
58 ep = &mp->mp_children;
63 snprintf( buf, sizeof( buf ),
66 "structuralObjectClass: %s\n"
71 "createTimestamp: %s\n"
72 "modifyTimestamp: %s\n",
74 mi->mi_oc_monitoredObject->soc_cname.bv_val,
75 mi->mi_oc_monitoredObject->soc_cname.bv_val,
76 mi->mi_ad_monitoredInfo->ad_cname.bv_val,
78 mi->mi_creatorsName.bv_val,
79 mi->mi_creatorsName.bv_val,
80 mi->mi_startTime.bv_val,
81 mi->mi_startTime.bv_val );
85 Debug( LDAP_DEBUG_ANY,
86 "monitor_subsys_thread_init: "
87 "unable to create entry \"cn=Max,%s\"\n",
88 ms->mss_ndn.bv_val, 0, 0 );
92 mp = monitor_entrypriv_create();
96 e->e_private = ( void * )mp;
98 mp->mp_flags = ms->mss_flags \
99 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
101 if ( monitor_cache_add( mi, e ) ) {
102 Debug( LDAP_DEBUG_ANY,
103 "monitor_subsys_thread_init: "
104 "unable to add entry \"cn=Max,%s\"\n",
105 ms->mss_ndn.bv_val, 0, 0 );
115 snprintf( buf, sizeof( buf ),
116 "dn: cn=Backload,%s\n"
118 "structuralObjectClass: %s\n"
122 "modifiersName: %s\n"
123 "createTimestamp: %s\n"
124 "modifyTimestamp: %s\n",
126 mi->mi_oc_monitoredObject->soc_cname.bv_val,
127 mi->mi_oc_monitoredObject->soc_cname.bv_val,
128 mi->mi_ad_monitoredInfo->ad_cname.bv_val,
129 mi->mi_creatorsName.bv_val,
130 mi->mi_creatorsName.bv_val,
131 mi->mi_startTime.bv_val,
132 mi->mi_startTime.bv_val );
134 e = str2entry( buf );
136 Debug( LDAP_DEBUG_ANY,
137 "monitor_subsys_thread_init: "
138 "unable to create entry \"cn=Backload,%s\"\n",
139 ms->mss_ndn.bv_val, 0, 0 );
143 mp = monitor_entrypriv_create();
147 e->e_private = ( void * )mp;
149 mp->mp_flags = ms->mss_flags \
150 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
152 if ( monitor_cache_add( mi, e ) ) {
153 Debug( LDAP_DEBUG_ANY,
154 "monitor_subsys_thread_init: "
155 "unable to add entry \"cn=Backload,%s\"\n",
156 ms->mss_ndn.bv_val, 0, 0 );
166 snprintf( buf, sizeof( buf ),
167 "dn: cn=Runqueue,%s\n"
169 "structuralObjectClass: %s\n"
173 "modifiersName: %s\n"
174 "createTimestamp: %s\n"
175 "modifyTimestamp: %s\n",
177 mi->mi_oc_monitoredObject->soc_cname.bv_val,
178 mi->mi_oc_monitoredObject->soc_cname.bv_val,
179 mi->mi_ad_monitoredInfo->ad_cname.bv_val,
180 mi->mi_creatorsName.bv_val,
181 mi->mi_creatorsName.bv_val,
182 mi->mi_startTime.bv_val,
183 mi->mi_startTime.bv_val );
185 e = str2entry( buf );
187 Debug( LDAP_DEBUG_ANY,
188 "monitor_subsys_thread_init: "
189 "unable to create entry \"cn=Runqueue,%s\"\n",
190 ms->mss_ndn.bv_val, 0, 0 );
194 mp = monitor_entrypriv_create();
198 e->e_private = ( void * )mp;
200 mp->mp_flags = ms->mss_flags \
201 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
203 if ( monitor_cache_add( mi, e ) ) {
204 Debug( LDAP_DEBUG_ANY,
205 "monitor_subsys_thread_init: "
206 "unable to add entry \"cn=Runqueue,%s\"\n",
207 ms->mss_ndn.bv_val, 0, 0 );
214 monitor_cache_release( mi, e_thread );
220 monitor_subsys_thread_update(
225 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
227 char buf[ BACKMONITOR_BUFSIZE ];
228 static struct berval backload_bv = BER_BVC( "cn=backload" );
229 static struct berval runqueue_bv = BER_BVC( "cn=runqueue" );
230 struct berval rdn, bv;
235 assert( mi != NULL );
237 dnRdn( &e->e_nname, &rdn );
238 if ( dn_match( &rdn, &backload_bv ))
240 else if ( dn_match( &rdn, &runqueue_bv ))
247 a = attr_find( e->e_attrs, mi->mi_ad_monitoredInfo );
251 snprintf( buf, sizeof( buf ), "%d",
252 ldap_pvt_thread_pool_backload( &connection_pool ) );
254 if ( len > a->a_vals[ 0 ].bv_len ) {
255 a->a_vals[ 0 ].bv_val = ber_memrealloc( a->a_vals[ 0 ].bv_val, len + 1 );
257 a->a_vals[ 0 ].bv_len = len;
258 AC_MEMCPY( a->a_vals[ 0 ].bv_val, buf, len + 1 );
261 attr_delete( &e->e_attrs, mi->mi_ad_monitoredInfo );
263 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
264 LDAP_STAILQ_FOREACH( re, &slapd_rq.run_list, rnext ) {
265 bv.bv_len = snprintf( buf, sizeof( buf ), "%s(%s)",
266 re->tname, re->tspec );
267 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL );
269 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
273 /* FIXME: touch modifyTimestamp? */