]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/rww.c
Update copyright statements
[openldap] / servers / slapd / back-monitor / rww.c
1 /* readw.c - deal with read waiters subsystem */
2 /*
3  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*
7  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
8  * 
9  * This work has beed deveolped for the OpenLDAP Foundation 
10  * in the hope that it may be useful to the Open Source community, 
11  * but WITHOUT ANY WARRANTY.
12  * 
13  * Permission is granted to anyone to use this software for any purpose
14  * on any computer system, and to alter it and redistribute it, subject
15  * to the following restrictions:
16  * 
17  * 1. The author and SysNet s.n.c. are not responsible for the consequences
18  *    of use of this software, no matter how awful, even if they arise from
19  *    flaws in it.
20  * 
21  * 2. The origin of this software must not be misrepresented, either by
22  *    explicit claim or by omission.  Since few users ever read sources,
23  *    credits should appear in the documentation.
24  * 
25  * 3. Altered versions must be plainly marked as such, and must not be
26  *    misrepresented as being the original software.  Since few users
27  *    ever read sources, credits should appear in the documentation.
28  *    SysNet s.n.c. cannot be responsible for the consequences of the
29  *    alterations.
30  * 
31  * 4. This notice may not be removed or altered.
32  */
33
34 #include "portable.h"
35
36 #include <stdio.h>
37
38 #include "slap.h"
39 #include "back-monitor.h"
40
41 static int monitor_subsys_readw_update_internal( struct monitorinfo *mi, Entry *e, int rw );
42
43 int 
44 monitor_subsys_readw_update( 
45         struct monitorinfo      *mi,
46         Entry                   *e
47 )
48 {
49         return monitor_subsys_readw_update_internal( mi, e, 0 );
50 }
51
52 int 
53 monitor_subsys_writew_update( 
54         struct monitorinfo      *mi,
55         Entry                   *e
56 )
57 {
58         return monitor_subsys_readw_update_internal( mi, e, 1 );
59 }
60
61 static int 
62 monitor_subsys_readw_update_internal( 
63         struct monitorinfo      *mi,
64         Entry                   *e,
65         int                     rw
66 )
67 {
68         Connection              *c;
69         int                     connindex;
70         int                     nconns, nwritewaiters, nreadwaiters;
71         
72         Attribute               *a;
73         struct berval           bv[2], *b = NULL;
74         char                    buf[1024];
75         
76         char                    *str = NULL;
77         int                     num = 0;
78
79         assert( mi != NULL );
80         assert( e != NULL );
81         
82         bv[1].bv_val = NULL;
83         
84         nconns = nwritewaiters = nreadwaiters = 0;
85         for ( c = connection_first( &connindex );
86                         c != NULL;
87                         c = connection_next( c, &connindex ), nconns++ ) {
88                 if ( c->c_writewaiter ) {
89                         nwritewaiters++;
90                 }
91                 if ( c->c_currentber != NULL ) {
92                         nreadwaiters++;
93                 }
94         }
95         connection_done(c);
96
97         switch ( rw ) {
98         case 0:
99                 str = "read waiters";
100                 num = nreadwaiters;
101                 break;
102         case 1:
103                 str = "write waiters";
104                 num = nwritewaiters;
105                 break;
106         }
107         snprintf( buf, sizeof( buf ), "%s=%d", str, num );
108
109         if ( ( a = attr_find( e->e_attrs, monitor_ad_desc ) ) != NULL ) {
110                 for ( b = a->a_vals; b[0].bv_val != NULL; b++ ) {
111                         if ( strncmp( b[0].bv_val, str, strlen( str ) ) == 0 ) {
112                                 free( b[0].bv_val );
113                                 ber_str2bv( buf, 0, 1, b );
114                                 break;
115                         }
116                 }
117         }
118
119         if ( b == NULL || b[0].bv_val == NULL ) {
120                 bv[0].bv_val = buf;
121                 bv[0].bv_len = strlen( buf );
122                 attr_merge( e, monitor_ad_desc, bv );
123         }
124
125         return( 0 );
126 }
127