]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/thread.c
notices
[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 1998-2003 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was initially developed by Pierangelo Masarati for inclusion
18  * in OpenLDAP Software.
19  */
20 /* This is an altered version */
21 /*
22  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
23  * 
24  * This work has beed deveolped for the OpenLDAP Foundation 
25  * in the hope that it may be useful to the Open Source community, 
26  * but WITHOUT ANY WARRANTY.
27  * 
28  * Permission is granted to anyone to use this software for any purpose
29  * on any computer system, and to alter it and redistribute it, subject
30  * to the following restrictions:
31  * 
32  * 1. The author and SysNet s.n.c. are not responsible for the consequences
33  *    of use of this software, no matter how awful, even if they arise from
34  *    flaws in it.
35  * 
36  * 2. The origin of this software must not be misrepresented, either by
37  *    explicit claim or by omission.  Since few users ever read sources,
38  *    credits should appear in the documentation.
39  * 
40  * 3. Altered versions must be plainly marked as such, and must not be
41  *    misrepresented as being the original software.  Since few users
42  *    ever read sources, credits should appear in the documentation.
43  *    SysNet s.n.c. cannot be responsible for the consequences of the
44  *    alterations.
45  * 
46  * 4. This notice may not be removed or altered.
47  */
48
49 #include "portable.h"
50
51 #include <stdio.h>
52 #include <ac/string.h>
53
54 #include "slap.h"
55 #include "back-monitor.h"
56
57 /*
58 *  * initializes log subentry
59 *   */
60 int
61 monitor_subsys_thread_init(
62         BackendDB       *be
63 )
64 {
65         struct monitorinfo      *mi;
66         Entry                   *e;
67         static char             buf[ BACKMONITOR_BUFSIZE ];
68         struct berval           bv;
69
70         mi = ( struct monitorinfo * )be->be_private;
71
72         if ( monitor_cache_get( mi, 
73                 &monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn, &e ) )
74         {
75 #ifdef NEW_LOGGING
76                 LDAP_LOG( OPERATION, CRIT,
77                         "monitor_subsys_thread_init: unable to get entry '%s'\n",
78                         monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn.bv_val, 0, 0 );
79 #else
80                 Debug( LDAP_DEBUG_ANY,
81                         "monitor_subsys_thread_init: unable to get entry '%s'\n",
82                         monitor_subsys[SLAPD_MONITOR_THREAD].mss_ndn.bv_val, 
83                         0, 0 );
84 #endif
85                 return( -1 );
86         }
87
88         /* initialize the thread number */
89         snprintf( buf, sizeof( buf ), "max=%d", connection_pool_max );
90
91         bv.bv_val = buf;
92         bv.bv_len = strlen( bv.bv_val );
93
94         attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL );
95
96         monitor_cache_release( mi, e );
97
98         return( 0 );
99 }
100
101 int 
102 monitor_subsys_thread_update( 
103         Operation               *op,
104         Entry                   *e
105 )
106 {
107         struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
108         Attribute               *a;
109         struct berval           *b = NULL;
110         char                    buf[ BACKMONITOR_BUFSIZE ];
111
112         assert( mi != NULL );
113
114         snprintf( buf, sizeof( buf ), "backload=%d", 
115                         ldap_pvt_thread_pool_backload( &connection_pool ) );
116
117         a = attr_find( e->e_attrs, mi->mi_ad_monitoredInfo );
118         if ( a != NULL ) {
119                 for ( b = a->a_vals; b[0].bv_val != NULL; b++ ) {
120                         if ( strncmp( b[0].bv_val, "backload=", 
121                                         sizeof( "backload=" ) - 1 ) == 0 ) {
122                                 free( b[0].bv_val );
123                                 ber_str2bv( buf, 0, 1, &b[0] );
124                                 break;
125                         }
126                 }
127         }
128
129         if ( b == NULL || b[0].bv_val == NULL ) {
130                 struct berval   bv;
131
132                 bv.bv_val = buf;
133                 bv.bv_len = strlen( buf );
134                 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
135                                 &bv, NULL );
136         }
137
138         return( 0 );
139 }
140