]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/thread.c
unifdef -UNEW_LOGGING
[openldap] / servers / slapd / back-monitor / thread.c
1 /* thread.c - deal with thread subsystem */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2001-2004 The OpenLDAP Foundation.
6  * Portions Copyright 2001-2003 Pierangelo Masarati.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
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>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Pierangelo Masarati for inclusion
19  * in OpenLDAP Software.
20  */
21
22 #include "portable.h"
23
24 #include <stdio.h>
25 #include <ac/string.h>
26
27 #include "slap.h"
28 #include "back-monitor.h"
29
30 /*
31 *  * initializes log subentry
32 *   */
33 int
34 monitor_subsys_thread_init(
35         BackendDB       *be
36 )
37 {
38         struct monitorinfo      *mi;
39         Entry                   *e;
40         static char             buf[ BACKMONITOR_BUFSIZE ];
41         struct berval           bv;
42
43         mi = ( struct monitorinfo * )be->be_private;
44
45         if ( monitor_cache_get( mi, 
46                 &monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn, &e ) )
47         {
48                 Debug( LDAP_DEBUG_ANY,
49                         "monitor_subsys_thread_init: unable to get entry '%s'\n",
50                         monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn.bv_val, 
51                         0, 0 );
52                 return( -1 );
53         }
54
55         /* initialize the thread number */
56         snprintf( buf, sizeof( buf ), "max=%d", connection_pool_max );
57
58         bv.bv_val = buf;
59         bv.bv_len = strlen( bv.bv_val );
60
61         attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL );
62
63         monitor_cache_release( mi, e );
64
65         return( 0 );
66 }
67
68 int 
69 monitor_subsys_thread_update( 
70         Operation               *op,
71         Entry                   *e
72 )
73 {
74         struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
75         Attribute               *a;
76         struct berval           *b = NULL;
77         char                    buf[ BACKMONITOR_BUFSIZE ];
78
79         assert( mi != NULL );
80
81         snprintf( buf, sizeof( buf ), "backload=%d", 
82                         ldap_pvt_thread_pool_backload( &connection_pool ) );
83
84         a = attr_find( e->e_attrs, mi->mi_ad_monitoredInfo );
85         if ( a != NULL ) {
86                 for ( b = a->a_vals; b[0].bv_val != NULL; b++ ) {
87                         if ( strncmp( b[0].bv_val, "backload=", 
88                                         sizeof( "backload=" ) - 1 ) == 0 ) {
89                                 free( b[0].bv_val );
90                                 ber_str2bv( buf, 0, 1, &b[0] );
91                                 break;
92                         }
93                 }
94         }
95
96         if ( b == NULL || b[0].bv_val == NULL ) {
97                 struct berval   bv;
98
99                 bv.bv_val = buf;
100                 bv.bv_len = strlen( buf );
101                 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
102                                 &bv, NULL );
103         }
104
105         return( 0 );
106 }
107