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"
31 * * initializes log subentry
34 monitor_subsys_thread_init(
41 Entry *e, **ep, *e_thread;
42 static char buf[ BACKMONITOR_BUFSIZE ];
44 mi = ( monitor_info_t * )be->be_private;
46 if ( monitor_cache_get( mi, &ms->mss_ndn, &e_thread ) ) {
47 Debug( LDAP_DEBUG_ANY,
48 "monitor_subsys_thread_init: unable to get entry \"%s\"\n",
54 mp = ( monitor_entry_t * )e_thread->e_private;
55 mp->mp_children = NULL;
56 ep = &mp->mp_children;
61 snprintf( buf, sizeof( buf ),
64 "structuralObjectClass: %s\n"
69 "createTimestamp: %s\n"
70 "modifyTimestamp: %s\n",
72 mi->mi_oc_monitoredObject->soc_cname.bv_val,
73 mi->mi_oc_monitoredObject->soc_cname.bv_val,
74 mi->mi_ad_monitoredInfo->ad_cname.bv_val,
76 mi->mi_creatorsName.bv_val,
77 mi->mi_creatorsName.bv_val,
78 mi->mi_startTime.bv_val,
79 mi->mi_startTime.bv_val );
83 Debug( LDAP_DEBUG_ANY,
84 "monitor_subsys_thread_init: "
85 "unable to create entry \"cn=Max,%s\"\n",
86 ms->mss_ndn.bv_val, 0, 0 );
90 mp = monitor_entrypriv_create();
94 e->e_private = ( void * )mp;
96 mp->mp_flags = ms->mss_flags \
97 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
99 if ( monitor_cache_add( mi, e ) ) {
100 Debug( LDAP_DEBUG_ANY,
101 "monitor_subsys_thread_init: "
102 "unable to add entry \"cn=Max,%s\"\n",
103 ms->mss_ndn.bv_val, 0, 0 );
113 snprintf( buf, sizeof( buf ),
114 "dn: cn=Backload,%s\n"
116 "structuralObjectClass: %s\n"
120 "modifiersName: %s\n"
121 "createTimestamp: %s\n"
122 "modifyTimestamp: %s\n",
124 mi->mi_oc_monitoredObject->soc_cname.bv_val,
125 mi->mi_oc_monitoredObject->soc_cname.bv_val,
126 mi->mi_ad_monitoredInfo->ad_cname.bv_val,
127 mi->mi_creatorsName.bv_val,
128 mi->mi_creatorsName.bv_val,
129 mi->mi_startTime.bv_val,
130 mi->mi_startTime.bv_val );
132 e = str2entry( buf );
134 Debug( LDAP_DEBUG_ANY,
135 "monitor_subsys_thread_init: "
136 "unable to create entry \"cn=Backload,%s\"\n",
137 ms->mss_ndn.bv_val, 0, 0 );
141 mp = monitor_entrypriv_create();
145 e->e_private = ( void * )mp;
147 mp->mp_flags = ms->mss_flags \
148 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
150 if ( monitor_cache_add( mi, e ) ) {
151 Debug( LDAP_DEBUG_ANY,
152 "monitor_subsys_thread_init: "
153 "unable to add entry \"cn=Backload,%s\"\n",
154 ms->mss_ndn.bv_val, 0, 0 );
161 monitor_cache_release( mi, e_thread );
167 monitor_subsys_thread_update(
172 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
174 char buf[ BACKMONITOR_BUFSIZE ];
175 static struct berval backload_bv = BER_BVC( "cn=backload" );
179 assert( mi != NULL );
181 dnRdn( &e->e_nname, &rdn );
182 if ( !dn_match( &rdn, &backload_bv ) ) {
186 a = attr_find( e->e_attrs, mi->mi_ad_monitoredInfo );
191 snprintf( buf, sizeof( buf ), "%d",
192 ldap_pvt_thread_pool_backload( &connection_pool ) );
194 if ( len > a->a_vals[ 0 ].bv_len ) {
195 a->a_vals[ 0 ].bv_val = ber_memrealloc( a->a_vals[ 0 ].bv_val, len + 1 );
197 a->a_vals[ 0 ].bv_len = len;
198 AC_MEMCPY( a->a_vals[ 0 ].bv_val, buf, len + 1 );
200 /* FIXME: touch modifyTimestamp? */