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, **ep, *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 ) ) {
51 Debug( LDAP_DEBUG_ANY,
52 "monitor_subsys_time_init: "
53 "unable to get entry \"%s\"\n",
54 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
58 mp = ( struct monitorentrypriv * )e_time->e_private;
59 mp->mp_children = NULL;
60 ep = &mp->mp_children;
62 snprintf( buf, sizeof( buf ),
65 "structuralObjectClass: %s\n"
70 "createTimestamp: %s\n"
71 "modifyTimestamp: %s\n",
72 monitor_subsys[SLAPD_MONITOR_TIME].mss_dn.bv_val,
73 mi->mi_oc_monitoredObject->soc_cname.bv_val,
74 mi->mi_oc_monitoredObject->soc_cname.bv_val,
75 mi->mi_ad_monitorTimestamp->ad_cname.bv_val,
76 mi->mi_startTime.bv_val,
77 mi->mi_creatorsName.bv_val,
78 mi->mi_creatorsName.bv_val,
79 mi->mi_startTime.bv_val,
80 mi->mi_startTime.bv_val );
84 Debug( LDAP_DEBUG_ANY,
85 "monitor_subsys_time_init: "
86 "unable to create entry \"cn=Start,%s\"\n",
87 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
91 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
92 e->e_private = ( void * )mp;
94 mp->mp_children = NULL;
95 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_TIME];
96 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_TIME].mss_flags \
97 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
99 if ( monitor_cache_add( mi, e ) ) {
100 Debug( LDAP_DEBUG_ANY,
101 "monitor_subsys_time_init: "
102 "unable to add entry \"cn=Start,%s\"\n",
103 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
113 snprintf( buf, sizeof( buf ),
114 "dn: cn=Current,%s\n"
116 "structuralObjectClass: %s\n"
120 "modifiersName: %s\n"
121 "createTimestamp: %s\n"
122 "modifyTimestamp: %s\n",
123 monitor_subsys[SLAPD_MONITOR_TIME].mss_dn.bv_val,
124 mi->mi_oc_monitoredObject->soc_cname.bv_val,
125 mi->mi_oc_monitoredObject->soc_cname.bv_val,
126 mi->mi_ad_monitorTimestamp->ad_cname.bv_val,
127 mi->mi_startTime.bv_val,
128 mi->mi_creatorsName.bv_val,
129 mi->mi_creatorsName.bv_val,
130 mi->mi_startTime.bv_val,
131 mi->mi_startTime.bv_val );
133 e = str2entry( buf );
135 Debug( LDAP_DEBUG_ANY,
136 "monitor_subsys_time_init: "
137 "unable to create entry \"cn=Current,%s\"\n",
138 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
142 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
143 e->e_private = ( void * )mp;
145 mp->mp_children = NULL;
146 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_TIME];
147 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_TIME].mss_flags \
148 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
150 if ( monitor_cache_add( mi, e ) ) {
151 Debug( LDAP_DEBUG_ANY,
152 "monitor_subsys_time_init: "
153 "unable to add entry \"cn=Current,%s\"\n",
154 monitor_subsys[SLAPD_MONITOR_TIME].mss_ndn.bv_val, 0, 0 );
161 monitor_cache_release( mi, e_time );
167 monitor_subsys_time_update(
172 struct monitorinfo *mi =
173 (struct monitorinfo *)op->o_bd->be_private;
175 static struct berval bv_current = BER_BVC( "cn=current" );
181 dnRdn( &e->e_nname, &rdn );
183 if ( dn_match( &rdn, &bv_current ) ) {
188 char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
193 currtime = slap_get_time();
195 #ifndef HAVE_GMTIME_R
196 ldap_pvt_thread_mutex_lock( &SLAPD_GLOBAL(gmtime_mutex) );
198 #ifdef HACK_LOCAL_TIME
199 # ifdef HAVE_LOCALTIME_R
200 tm = localtime_r( &currtime, &tm_buf );
202 tm = localtime( &currtime );
203 # endif /* HAVE_LOCALTIME_R */
204 lutil_localtime( tmbuf, sizeof( tmbuf ), tm, -timezone );
205 #else /* !HACK_LOCAL_TIME */
206 # ifdef HAVE_GMTIME_R
207 tm = gmtime_r( &currtime, &tm_buf );
209 tm = gmtime( &currtime );
210 # endif /* HAVE_GMTIME_R */
211 lutil_gentime( tmbuf, sizeof( tmbuf ), tm );
212 #endif /* !HACK_LOCAL_TIME */
213 #ifndef HAVE_GMTIME_R
214 ldap_pvt_thread_mutex_unlock( &SLAPD_GLOBAL(gmtime_mutex) );
217 len = strlen( tmbuf );
219 a = attr_find( e->e_attrs, mi->mi_ad_monitorTimestamp );
224 assert( len == a->a_vals[0].bv_len );
225 AC_MEMCPY( a->a_vals[0].bv_val, tmbuf, len );