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(
42 Entry *e, **ep, *e_time;
44 char buf[ BACKMONITOR_BUFSIZE ];
48 mi = ( monitor_info_t * )be->be_private;
50 if ( monitor_cache_get( mi,
51 &ms->mss_ndn, &e_time ) ) {
52 Debug( LDAP_DEBUG_ANY,
53 "monitor_subsys_time_init: "
54 "unable to get entry \"%s\"\n",
55 ms->mss_ndn.bv_val, 0, 0 );
59 mp = ( monitor_entry_t * )e_time->e_private;
60 mp->mp_children = NULL;
61 ep = &mp->mp_children;
63 snprintf( buf, sizeof( buf ),
66 "structuralObjectClass: %s\n"
71 "createTimestamp: %s\n"
72 "modifyTimestamp: %s\n",
74 mi->mi_oc_monitoredObject->soc_cname.bv_val,
75 mi->mi_oc_monitoredObject->soc_cname.bv_val,
76 mi->mi_ad_monitorTimestamp->ad_cname.bv_val,
77 mi->mi_startTime.bv_val,
78 mi->mi_creatorsName.bv_val,
79 mi->mi_creatorsName.bv_val,
80 mi->mi_startTime.bv_val,
81 mi->mi_startTime.bv_val );
85 Debug( LDAP_DEBUG_ANY,
86 "monitor_subsys_time_init: "
87 "unable to create entry \"cn=Start,%s\"\n",
88 ms->mss_ndn.bv_val, 0, 0 );
92 mp = monitor_entrypriv_create();
96 e->e_private = ( void * )mp;
98 mp->mp_flags = ms->mss_flags \
99 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
101 if ( monitor_cache_add( mi, e ) ) {
102 Debug( LDAP_DEBUG_ANY,
103 "monitor_subsys_time_init: "
104 "unable to add entry \"cn=Start,%s\"\n",
105 ms->mss_ndn.bv_val, 0, 0 );
115 snprintf( buf, sizeof( buf ),
116 "dn: cn=Current,%s\n"
118 "structuralObjectClass: %s\n"
122 "modifiersName: %s\n"
123 "createTimestamp: %s\n"
124 "modifyTimestamp: %s\n",
126 mi->mi_oc_monitoredObject->soc_cname.bv_val,
127 mi->mi_oc_monitoredObject->soc_cname.bv_val,
128 mi->mi_ad_monitorTimestamp->ad_cname.bv_val,
129 mi->mi_startTime.bv_val,
130 mi->mi_creatorsName.bv_val,
131 mi->mi_creatorsName.bv_val,
132 mi->mi_startTime.bv_val,
133 mi->mi_startTime.bv_val );
135 e = str2entry( buf );
137 Debug( LDAP_DEBUG_ANY,
138 "monitor_subsys_time_init: "
139 "unable to create entry \"cn=Current,%s\"\n",
140 ms->mss_ndn.bv_val, 0, 0 );
144 mp = monitor_entrypriv_create();
148 e->e_private = ( void * )mp;
150 mp->mp_flags = ms->mss_flags \
151 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
153 if ( monitor_cache_add( mi, e ) ) {
154 Debug( LDAP_DEBUG_ANY,
155 "monitor_subsys_time_init: "
156 "unable to add entry \"cn=Current,%s\"\n",
157 ms->mss_ndn.bv_val, 0, 0 );
164 monitor_cache_release( mi, e_time );
170 monitor_subsys_time_update(
175 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
176 static struct berval bv_current = BER_BVC( "cn=current" );
182 dnRdn( &e->e_nname, &rdn );
184 if ( dn_match( &rdn, &bv_current ) ) {
189 char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
194 currtime = slap_get_time();
196 #ifndef HAVE_GMTIME_R
197 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
199 #ifdef HACK_LOCAL_TIME
200 # ifdef HAVE_LOCALTIME_R
201 tm = localtime_r( &currtime, &tm_buf );
203 tm = localtime( &currtime );
204 # endif /* HAVE_LOCALTIME_R */
205 lutil_localtime( tmbuf, sizeof( tmbuf ), tm, -timezone );
206 #else /* !HACK_LOCAL_TIME */
207 # ifdef HAVE_GMTIME_R
208 tm = gmtime_r( &currtime, &tm_buf );
210 tm = gmtime( &currtime );
211 # endif /* HAVE_GMTIME_R */
212 lutil_gentime( tmbuf, sizeof( tmbuf ), tm );
213 #endif /* !HACK_LOCAL_TIME */
214 #ifndef HAVE_GMTIME_R
215 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
218 len = strlen( tmbuf );
220 a = attr_find( e->e_attrs, mi->mi_ad_monitorTimestamp );
225 assert( len == a->a_vals[ 0 ].bv_len );
226 AC_MEMCPY( a->a_vals[ 0 ].bv_val, tmbuf, len );