2001-07-15 01:34:24 +08:00
|
|
|
/* thread.c - deal with thread subsystem */
|
2003-11-27 10:35:20 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2004-01-02 03:15:16 +08:00
|
|
|
* Copyright 2001-2004 The OpenLDAP Foundation.
|
2003-12-09 01:41:40 +08:00
|
|
|
* Portions Copyright 2001-2003 Pierangelo Masarati.
|
2003-11-27 10:35:20 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by Pierangelo Masarati for inclusion
|
|
|
|
* in OpenLDAP Software.
|
2001-07-15 01:34:24 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2003-05-15 05:36:34 +08:00
|
|
|
#include <ac/string.h>
|
2001-07-15 01:34:24 +08:00
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "back-monitor.h"
|
|
|
|
|
2001-12-10 17:50:06 +08:00
|
|
|
/*
|
|
|
|
* * initializes log subentry
|
|
|
|
* */
|
|
|
|
int
|
|
|
|
monitor_subsys_thread_init(
|
2004-11-08 18:10:15 +08:00
|
|
|
BackendDB *be,
|
|
|
|
monitorsubsys *ms
|
2001-12-10 17:50:06 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
struct monitorinfo *mi;
|
2004-09-13 06:12:58 +08:00
|
|
|
struct monitorentrypriv *mp;
|
|
|
|
Entry *e, **ep, *e_thread;
|
2003-04-19 01:17:18 +08:00
|
|
|
static char buf[ BACKMONITOR_BUFSIZE ];
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
mi = ( struct monitorinfo * )be->be_private;
|
|
|
|
|
2004-11-08 18:10:15 +08:00
|
|
|
if ( monitor_cache_get( mi, &ms->mss_ndn, &e_thread ) ) {
|
2001-12-10 17:50:06 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
2004-09-13 06:12:58 +08:00
|
|
|
"monitor_subsys_thread_init: unable to get entry \"%s\"\n",
|
2004-11-08 18:10:15 +08:00
|
|
|
ms->mss_ndn.bv_val,
|
2001-12-27 23:16:12 +08:00
|
|
|
0, 0 );
|
2001-12-10 17:50:06 +08:00
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
2004-09-13 06:12:58 +08:00
|
|
|
mp = ( struct monitorentrypriv * )e_thread->e_private;
|
|
|
|
mp->mp_children = NULL;
|
|
|
|
ep = &mp->mp_children;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Max
|
|
|
|
*/
|
|
|
|
snprintf( buf, sizeof( buf ),
|
|
|
|
"dn: cn=Max,%s\n"
|
|
|
|
"objectClass: %s\n"
|
|
|
|
"structuralObjectClass: %s\n"
|
|
|
|
"cn: Max\n"
|
|
|
|
"%s: %d\n"
|
|
|
|
"creatorsName: %s\n"
|
|
|
|
"modifiersName: %s\n"
|
|
|
|
"createTimestamp: %s\n"
|
|
|
|
"modifyTimestamp: %s\n",
|
2004-11-08 18:10:15 +08:00
|
|
|
ms->mss_dn.bv_val,
|
2004-09-13 06:12:58 +08:00
|
|
|
mi->mi_oc_monitoredObject->soc_cname.bv_val,
|
|
|
|
mi->mi_oc_monitoredObject->soc_cname.bv_val,
|
|
|
|
mi->mi_ad_monitoredInfo->ad_cname.bv_val,
|
2004-10-06 13:51:38 +08:00
|
|
|
connection_pool_max,
|
2004-09-13 06:12:58 +08:00
|
|
|
mi->mi_creatorsName.bv_val,
|
|
|
|
mi->mi_creatorsName.bv_val,
|
|
|
|
mi->mi_startTime.bv_val,
|
|
|
|
mi->mi_startTime.bv_val );
|
|
|
|
|
|
|
|
e = str2entry( buf );
|
|
|
|
if ( e == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"monitor_subsys_thread_init: "
|
|
|
|
"unable to create entry \"cn=Max,%s\"\n",
|
2004-11-08 18:10:15 +08:00
|
|
|
ms->mss_ndn.bv_val, 0, 0 );
|
2004-09-13 06:12:58 +08:00
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
|
|
|
|
e->e_private = ( void * )mp;
|
|
|
|
mp->mp_next = NULL;
|
|
|
|
mp->mp_children = NULL;
|
2004-11-08 18:10:15 +08:00
|
|
|
mp->mp_info = ms;
|
|
|
|
mp->mp_flags = ms->mss_flags \
|
2004-09-13 06:12:58 +08:00
|
|
|
| MONITOR_F_SUB | MONITOR_F_PERSISTENT;
|
|
|
|
|
|
|
|
if ( monitor_cache_add( mi, e ) ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"monitor_subsys_thread_init: "
|
|
|
|
"unable to add entry \"cn=Max,%s\"\n",
|
2004-11-08 18:10:15 +08:00
|
|
|
ms->mss_ndn.bv_val, 0, 0 );
|
2004-09-13 06:12:58 +08:00
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
*ep = e;
|
|
|
|
ep = &mp->mp_next;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Backload
|
|
|
|
*/
|
|
|
|
snprintf( buf, sizeof( buf ),
|
|
|
|
"dn: cn=Backload,%s\n"
|
|
|
|
"objectClass: %s\n"
|
|
|
|
"structuralObjectClass: %s\n"
|
|
|
|
"cn: Backload\n"
|
|
|
|
"%s: 0\n"
|
|
|
|
"creatorsName: %s\n"
|
|
|
|
"modifiersName: %s\n"
|
|
|
|
"createTimestamp: %s\n"
|
|
|
|
"modifyTimestamp: %s\n",
|
2004-11-08 18:10:15 +08:00
|
|
|
ms->mss_dn.bv_val,
|
2004-09-13 06:12:58 +08:00
|
|
|
mi->mi_oc_monitoredObject->soc_cname.bv_val,
|
|
|
|
mi->mi_oc_monitoredObject->soc_cname.bv_val,
|
|
|
|
mi->mi_ad_monitoredInfo->ad_cname.bv_val,
|
|
|
|
mi->mi_creatorsName.bv_val,
|
|
|
|
mi->mi_creatorsName.bv_val,
|
|
|
|
mi->mi_startTime.bv_val,
|
|
|
|
mi->mi_startTime.bv_val );
|
|
|
|
|
|
|
|
e = str2entry( buf );
|
|
|
|
if ( e == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"monitor_subsys_thread_init: "
|
|
|
|
"unable to create entry \"cn=Backload,%s\"\n",
|
2004-11-08 18:10:15 +08:00
|
|
|
ms->mss_ndn.bv_val, 0, 0 );
|
2004-09-13 06:12:58 +08:00
|
|
|
return( -1 );
|
|
|
|
}
|
2001-12-10 17:50:06 +08:00
|
|
|
|
2004-09-13 06:12:58 +08:00
|
|
|
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
|
|
|
|
e->e_private = ( void * )mp;
|
|
|
|
mp->mp_next = NULL;
|
|
|
|
mp->mp_children = NULL;
|
2004-11-08 18:10:15 +08:00
|
|
|
mp->mp_info = ms;
|
|
|
|
mp->mp_flags = ms->mss_flags \
|
2004-09-13 06:12:58 +08:00
|
|
|
| MONITOR_F_SUB | MONITOR_F_PERSISTENT;
|
2001-12-10 17:50:06 +08:00
|
|
|
|
2004-09-13 06:12:58 +08:00
|
|
|
if ( monitor_cache_add( mi, e ) ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"monitor_subsys_thread_init: "
|
|
|
|
"unable to add entry \"cn=Backload,%s\"\n",
|
2004-11-08 18:10:15 +08:00
|
|
|
ms->mss_ndn.bv_val, 0, 0 );
|
2004-09-13 06:12:58 +08:00
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
*ep = e;
|
|
|
|
ep = &mp->mp_next;
|
2001-12-10 17:50:06 +08:00
|
|
|
|
2004-09-13 06:12:58 +08:00
|
|
|
monitor_cache_release( mi, e_thread );
|
2001-12-10 17:50:06 +08:00
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
2001-07-15 01:34:24 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
monitor_subsys_thread_update(
|
2003-04-12 07:08:16 +08:00
|
|
|
Operation *op,
|
2001-07-15 01:34:24 +08:00
|
|
|
Entry *e
|
|
|
|
)
|
|
|
|
{
|
2004-09-13 06:12:58 +08:00
|
|
|
struct monitorinfo *mi =
|
|
|
|
(struct monitorinfo *)op->o_bd->be_private;
|
2001-07-15 01:34:24 +08:00
|
|
|
Attribute *a;
|
2003-04-19 01:17:18 +08:00
|
|
|
char buf[ BACKMONITOR_BUFSIZE ];
|
2004-09-13 06:12:58 +08:00
|
|
|
static struct berval backload_bv = BER_BVC( "cn=backload" );
|
|
|
|
struct berval rdn;
|
|
|
|
ber_len_t len;
|
2001-07-15 01:34:24 +08:00
|
|
|
|
2003-04-12 07:08:16 +08:00
|
|
|
assert( mi != NULL );
|
|
|
|
|
2004-09-13 06:12:58 +08:00
|
|
|
dnRdn( &e->e_nname, &rdn );
|
|
|
|
if ( !dn_match( &rdn, &backload_bv ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2001-07-15 01:34:24 +08:00
|
|
|
|
2003-05-18 01:19:16 +08:00
|
|
|
a = attr_find( e->e_attrs, mi->mi_ad_monitoredInfo );
|
2004-09-13 06:12:58 +08:00
|
|
|
if ( a == NULL ) {
|
|
|
|
return -1;
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
|
|
|
|
2004-09-13 06:12:58 +08:00
|
|
|
snprintf( buf, sizeof( buf ), "%d",
|
2004-10-06 13:51:38 +08:00
|
|
|
ldap_pvt_thread_pool_backload( &connection_pool ) );
|
2004-09-13 06:12:58 +08:00
|
|
|
len = strlen( buf );
|
|
|
|
if ( len > a->a_vals[ 0 ].bv_len ) {
|
|
|
|
a->a_vals[ 0 ].bv_val = ber_memrealloc( a->a_vals[ 0 ].bv_val, len + 1 );
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
2004-09-13 06:12:58 +08:00
|
|
|
a->a_vals[ 0 ].bv_len = len;
|
|
|
|
AC_MEMCPY( a->a_vals[ 0 ].bv_val, buf, len + 1 );
|
2001-07-15 01:34:24 +08:00
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|