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"
76 "createTimestamp: %s\n"
77 "modifyTimestamp: %s\n",
78 monitor_subsys[SLAPD_MONITOR_TIME].mss_dn.bv_val,
79 mi->mi_oc_monitoredObject->soc_cname.bv_val,
80 mi->mi_oc_monitoredObject->soc_cname.bv_val,
81 mi->mi_ad_monitorTimestamp->ad_cname.bv_val,
82 mi->mi_startTime.bv_val,
83 mi->mi_creatorsName.bv_val,
84 mi->mi_creatorsName.bv_val,
85 mi->mi_startTime.bv_val,
86 mi->mi_startTime.bv_val );
91 LDAP_LOG( OPERATION, CRIT,
92 "monitor_subsys_time_init: "
93 "unable to create entry 'cn=Start,%s'\n",
94 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
96 Debug( LDAP_DEBUG_ANY,
97 "monitor_subsys_time_init: "
98 "unable to create entry 'cn=Start,%s'\n%s%s",
99 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
105 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
106 e->e_private = ( void * )mp;
108 mp->mp_children = NULL;
109 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_TIME];
110 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_TIME].mss_flags \
111 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
113 if ( monitor_cache_add( mi, e ) ) {
115 LDAP_LOG( OPERATION, CRIT,
116 "monitor_subsys_time_init: "
117 "unable to add entry 'cn=Start,%s'\n",
118 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
120 Debug( LDAP_DEBUG_ANY,
121 "monitor_subsys_time_init: "
122 "unable to add entry 'cn=Start,%s'\n%s%s",
123 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
134 snprintf( buf, sizeof( buf ),
135 "dn: cn=Current,%s\n"
137 "structuralObjectClass: %s\n"
141 "modifiersName: %s\n"
142 "createTimestamp: %s\n"
143 "modifyTimestamp: %s\n",
144 monitor_subsys[SLAPD_MONITOR_TIME].mss_dn.bv_val,
145 mi->mi_oc_monitoredObject->soc_cname.bv_val,
146 mi->mi_oc_monitoredObject->soc_cname.bv_val,
147 mi->mi_ad_monitorTimestamp->ad_cname.bv_val,
148 mi->mi_startTime.bv_val,
149 mi->mi_creatorsName.bv_val,
150 mi->mi_creatorsName.bv_val,
151 mi->mi_startTime.bv_val,
152 mi->mi_startTime.bv_val );
154 e = str2entry( buf );
157 LDAP_LOG( OPERATION, CRIT,
158 "monitor_subsys_time_init: "
159 "unable to create entry 'cn=Current,%s'\n",
160 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
162 Debug( LDAP_DEBUG_ANY,
163 "monitor_subsys_time_init: "
164 "unable to create entry 'cn=Current,%s'\n%s%s",
165 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
171 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
172 e->e_private = ( void * )mp;
174 mp->mp_children = NULL;
175 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_TIME];
176 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_TIME].mss_flags \
177 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
179 if ( monitor_cache_add( mi, e ) ) {
181 LDAP_LOG( OPERATION, CRIT,
182 "monitor_subsys_time_init: "
183 "unable to add entry 'cn=Current,%s'\n",
184 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
186 Debug( LDAP_DEBUG_ANY,
187 "monitor_subsys_time_init: "
188 "unable to add entry 'cn=Current,%s'\n%s%s",
189 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val,
197 mp = ( struct monitorentrypriv * )e_time->e_private;
198 mp->mp_children = e_tmp;
200 monitor_cache_release( mi, e_time );
206 monitor_subsys_time_update(
211 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
216 if ( strncmp( e->e_nname.bv_val, "cn=current",
217 sizeof("cn=current") - 1 ) == 0 ) {
222 char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
227 currtime = slap_get_time();
229 #ifndef HAVE_GMTIME_R
230 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
232 #ifdef HACK_LOCAL_TIME
233 # ifdef HAVE_LOCALTIME_R
234 tm = localtime_r( &currtime, &tm_buf );
236 tm = localtime( &currtime );
237 # endif /* HAVE_LOCALTIME_R */
238 lutil_localtime( tmbuf, sizeof( tmbuf ), tm, -timezone );
239 #else /* !HACK_LOCAL_TIME */
240 # ifdef HAVE_GMTIME_R
241 tm = gmtime_r( &currtime, &tm_buf );
243 tm = gmtime( &currtime );
244 # endif /* HAVE_GMTIME_R */
245 lutil_gentime( tmbuf, sizeof( tmbuf ), tm );
246 #endif /* !HACK_LOCAL_TIME */
247 #ifndef HAVE_GMTIME_R
248 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
251 len = strlen( tmbuf );
253 a = attr_find( e->e_attrs, mi->mi_ad_monitorTimestamp );
258 assert( len == a->a_vals[0].bv_len );
259 AC_MEMCPY( a->a_vals[0].bv_val, tmbuf, len );