]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/thread.c
Happy new year
[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 #ifdef NEW_LOGGING
49                 LDAP_LOG( OPERATION, CRIT,
50                         "monitor_subsys_thread_init: unable to get entry '%s'\n",
51                         monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn.bv_val, 0, 0 );
52 #else
53                 Debug( LDAP_DEBUG_ANY,
54                         "monitor_subsys_thread_init: unable to get entry '%s'\n",
55                         monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn.bv_val, 
56                         0, 0 );
57 #endif
58                 return( -1 );
59         }
60
61         /* initialize the thread number */
62         snprintf( buf, sizeof( buf ), "max=%d", connection_pool_max );
63
64         bv.bv_val = buf;
65         bv.bv_len = strlen( bv.bv_val );
66
67         attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL );
68
69         monitor_cache_release( mi, e );
70
71         return( 0 );
72 }
73
74 int 
75 monitor_subsys_thread_update( 
76         Operation               *op,
77         Entry                   *e
78 )
79 {
80         struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
81         Attribute               *a;
82         struct berval           *b = NULL;
83         char                    buf[ BACKMONITOR_BUFSIZE ];
84
85         assert( mi != NULL );
86
87         snprintf( buf, sizeof( buf ), "backload=%d", 
88                         ldap_pvt_thread_pool_backload( &connection_pool ) );
89
90         a = attr_find( e->e_attrs, mi->mi_ad_monitoredInfo );
91         if ( a != NULL ) {
92                 for ( b = a->a_vals; b[0].bv_val != NULL; b++ ) {
93                         if ( strncmp( b[0].bv_val, "backload=", 
94                                         sizeof( "backload=" ) - 1 ) == 0 ) {
95                                 free( b[0].bv_val );
96                                 ber_str2bv( buf, 0, 1, &b[0] );
97                                 break;
98                         }
99                 }
100         }
101
102         if ( b == NULL || b[0].bv_val == NULL ) {
103                 struct berval   bv;
104
105                 bv.bv_val = buf;
106                 bv.bv_len = strlen( buf );
107                 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
108                                 &bv, NULL );
109         }
110
111         return( 0 );
112 }
113