1 /* time.c - deal with time subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2004 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
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>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
25 #include <ac/string.h>
31 #include "proto-slap.h"
32 #include "back-monitor.h"
35 monitor_subsys_time_init(
39 struct monitorinfo *mi;
41 Entry *e, *e_tmp, *e_time;
42 struct monitorentrypriv *mp;
43 char buf[ BACKMONITOR_BUFSIZE ];
47 mi = ( struct monitorinfo * )be->be_private;
49 if ( monitor_cache_get( mi,
50 &monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn, &e_time ) ) {
52 LDAP_LOG( OPERATION, CRIT,
53 "monitor_subsys_time_init: "
54 "unable to get entry '%s'\n",
55 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
57 Debug( LDAP_DEBUG_ANY,
58 "monitor_subsys_time_init: "
59 "unable to get entry '%s'\n%s%s",
60 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
68 snprintf( buf, sizeof( buf ),
71 "structuralObjectClass: %s\n"
74 "createTimestamp: %s\n"
75 "modifyTimestamp: %s\n",
76 monitor_subsys[SLAPD_MONITOR_TIME].mss_dn.bv_val,
77 mi->mi_oc_monitoredObject->soc_cname.bv_val,
78 mi->mi_oc_monitoredObject->soc_cname.bv_val,
79 mi->mi_ad_monitorTimestamp->ad_cname.bv_val,
80 mi->mi_startTime.bv_val,
81 mi->mi_startTime.bv_val,
82 mi->mi_startTime.bv_val );
87 LDAP_LOG( OPERATION, CRIT,
88 "monitor_subsys_time_init: "
89 "unable to create entry 'cn=Start,%s'\n",
90 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
92 Debug( LDAP_DEBUG_ANY,
93 "monitor_subsys_time_init: "
94 "unable to create entry 'cn=Start,%s'\n%s%s",
95 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
101 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
102 e->e_private = ( void * )mp;
104 mp->mp_children = NULL;
105 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_TIME];
106 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_TIME].mss_flags \
107 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
109 if ( monitor_cache_add( mi, e ) ) {
111 LDAP_LOG( OPERATION, CRIT,
112 "monitor_subsys_time_init: "
113 "unable to add entry 'cn=Start,%s'\n",
114 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
116 Debug( LDAP_DEBUG_ANY,
117 "monitor_subsys_time_init: "
118 "unable to add entry 'cn=Start,%s'\n%s%s",
119 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
130 snprintf( buf, sizeof( buf ),
131 "dn: cn=Current,%s\n"
133 "structuralObjectClass: %s\n"
136 "createTimestamp: %s\n"
137 "modifyTimestamp: %s\n",
138 monitor_subsys[SLAPD_MONITOR_TIME].mss_dn.bv_val,
139 mi->mi_oc_monitoredObject->soc_cname.bv_val,
140 mi->mi_oc_monitoredObject->soc_cname.bv_val,
141 mi->mi_ad_monitorTimestamp->ad_cname.bv_val,
142 mi->mi_startTime.bv_val,
143 mi->mi_startTime.bv_val,
144 mi->mi_startTime.bv_val );
146 e = str2entry( buf );
149 LDAP_LOG( OPERATION, CRIT,
150 "monitor_subsys_time_init: "
151 "unable to create entry 'cn=Current,%s'\n",
152 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
154 Debug( LDAP_DEBUG_ANY,
155 "monitor_subsys_time_init: "
156 "unable to create entry 'cn=Current,%s'\n%s%s",
157 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
163 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
164 e->e_private = ( void * )mp;
166 mp->mp_children = NULL;
167 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_TIME];
168 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_TIME].mss_flags \
169 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
171 if ( monitor_cache_add( mi, e ) ) {
173 LDAP_LOG( OPERATION, CRIT,
174 "monitor_subsys_time_init: "
175 "unable to add entry 'cn=Current,%s'\n",
176 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
178 Debug( LDAP_DEBUG_ANY,
179 "monitor_subsys_time_init: "
180 "unable to add entry 'cn=Current,%s'\n%s%s",
181 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
189 mp = ( struct monitorentrypriv * )e_time->e_private;
190 mp->mp_children = e_tmp;
192 monitor_cache_release( mi, e_time );
198 monitor_subsys_time_update(
203 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
208 if ( strncmp( e->e_nname.bv_val, "cn=current",
209 sizeof("cn=current") - 1 ) == 0 ) {
214 char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
219 currtime = slap_get_time();
221 #ifndef HAVE_GMTIME_R
222 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
224 #ifdef HACK_LOCAL_TIME
225 # ifdef HAVE_LOCALTIME_R
226 tm = localtime_r( &currtime, &tm_buf );
228 tm = localtime( &currtime );
229 # endif /* HAVE_LOCALTIME_R */
230 lutil_localtime( tmbuf, sizeof( tmbuf ), tm, -timezone );
231 #else /* !HACK_LOCAL_TIME */
232 # ifdef HAVE_GMTIME_R
233 tm = gmtime_r( &currtime, &tm_buf );
235 tm = gmtime( &currtime );
236 # endif /* HAVE_GMTIME_R */
237 lutil_gentime( tmbuf, sizeof( tmbuf ), tm );
238 #endif /* !HACK_LOCAL_TIME */
239 #ifndef HAVE_GMTIME_R
240 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
243 len = strlen( tmbuf );
245 a = attr_find( e->e_attrs, mi->mi_ad_monitorTimestamp );
250 assert( len == a->a_vals[0].bv_len );
251 AC_MEMCPY( a->a_vals[0].bv_val, tmbuf, len );