1 /* time.c - deal with time subsystem */
3 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
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.
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:
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
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.
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
31 * 4. This notice may not be removed or altered.
37 #include <ac/string.h>
41 #include "proto-slap.h"
42 #include "back-monitor.h"
45 monitor_subsys_time_init(
49 struct monitorinfo *mi;
51 Entry *e, *e_tmp, *e_time;
52 struct monitorentrypriv *mp;
53 char buf[1024], tmbuf[20];
58 mi = ( struct monitorinfo * )be->be_private;
60 if ( monitor_cache_get( mi,
61 &monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn, &e_time ) ) {
63 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
64 "monitor_subsys_time_init: "
65 "unable to get entry '%s'\n",
66 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val ));
68 Debug( LDAP_DEBUG_ANY,
69 "monitor_subsys_time_init: "
70 "unable to get entry '%s'\n%s%s",
71 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
82 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
83 ltm = gmtime( &starttime );
84 strftime( tmbuf, sizeof(tmbuf), "%Y%m%d%H%M%SZ", ltm );
85 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
86 snprintf( buf, sizeof( buf ),
88 SLAPD_MONITOR_OBJECTCLASSES
91 monitor_subsys[SLAPD_MONITOR_TIME].mss_dn.bv_val,
97 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
98 "monitor_subsys_time_init: "
99 "unable to create entry 'cn=Start,%s'\n",
100 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val ));
102 Debug( LDAP_DEBUG_ANY,
103 "monitor_subsys_time_init: "
104 "unable to create entry 'cn=Start,%s'\n%s%s",
105 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
111 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
112 e->e_private = ( void * )mp;
114 mp->mp_children = NULL;
115 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_TIME];
116 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_TIME].mss_flags \
117 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
119 if ( monitor_cache_add( mi, e ) ) {
121 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
122 "monitor_subsys_time_init: "
123 "unable to add entry 'cn=Start,%s'\n",
124 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val ));
126 Debug( LDAP_DEBUG_ANY,
127 "monitor_subsys_time_init: "
128 "unable to add entry 'cn=Start,%s'\n%s%s",
129 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
140 snprintf( buf, sizeof( buf ),
141 "dn: cn=Current,%s\n"
142 SLAPD_MONITOR_OBJECTCLASSES
145 monitor_subsys[SLAPD_MONITOR_TIME].mss_dn.bv_val,
148 e = str2entry( buf );
151 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
152 "monitor_subsys_time_init: "
153 "unable to create entry 'cn=Current,%s'\n",
154 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val ));
156 Debug( LDAP_DEBUG_ANY,
157 "monitor_subsys_time_init: "
158 "unable to create entry 'cn=Current,%s'\n%s%s",
159 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
165 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
166 e->e_private = ( void * )mp;
168 mp->mp_children = NULL;
169 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_TIME];
170 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_TIME].mss_flags \
171 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
173 if ( monitor_cache_add( mi, e ) ) {
175 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
176 "monitor_subsys_time_init: "
177 "unable to add entry 'cn=Current,%s'\n",
178 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val ));
180 Debug( LDAP_DEBUG_ANY,
181 "monitor_subsys_time_init: "
182 "unable to add entry 'cn=Current,%s'\n%s%s",
183 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
191 mp = ( struct monitorentrypriv * )e_time->e_private;
192 mp->mp_children = e_tmp;
194 monitor_cache_release( mi, e_time );
200 monitor_subsys_time_update(
201 struct monitorinfo *mi,
208 struct berval bv[ 2 ];
212 static int init_start = 0;
217 if ( init_start == 0 && strncmp( e->e_nname.bv_val, "cn=START",
218 sizeof("cn=START")-1 ) == 0 ) {
219 currenttime = starttime;
222 } else if ( strncmp( e->e_nname.bv_val, "cn=CURRENT",
223 sizeof("cn=CURRENT")-1 ) == 0 ) {
224 currenttime = slap_get_time();
230 a = attr_find( e->e_attrs, monitor_ad_desc );
236 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
237 ltm = gmtime( ¤ttime );
238 strftime( tmbuf, sizeof(tmbuf), "%Y%m%d%H%M%SZ", ltm );
239 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
241 len = strlen( tmbuf );
242 assert( len == a->a_vals[0].bv_len );
243 AC_MEMCPY( a->a_vals[0].bv_val, tmbuf, len );