1 /* time.c - deal with time subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2006 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_update(
41 monitor_subsys_time_init(
43 monitor_subsys_t *ms )
47 Entry *e, **ep, *e_time;
49 char buf[ BACKMONITOR_BUFSIZE ];
54 ms->mss_update = monitor_subsys_time_update;
56 mi = ( monitor_info_t * )be->be_private;
58 if ( monitor_cache_get( mi,
59 &ms->mss_ndn, &e_time ) ) {
60 Debug( LDAP_DEBUG_ANY,
61 "monitor_subsys_time_init: "
62 "unable to get entry \"%s\"\n",
63 ms->mss_ndn.bv_val, 0, 0 );
67 mp = ( monitor_entry_t * )e_time->e_private;
68 mp->mp_children = NULL;
69 ep = &mp->mp_children;
71 BER_BVSTR( &bv, "cn=Start" );
72 e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &bv,
73 mi->mi_oc_monitoredObject, mi, NULL, NULL );
75 Debug( LDAP_DEBUG_ANY,
76 "monitor_subsys_time_init: "
77 "unable to create entry \"cn=Start,%s\"\n",
78 ms->mss_ndn.bv_val, 0, 0 );
81 attr_merge_normalize_one( e, mi->mi_ad_monitorTimestamp,
82 &mi->mi_startTime, NULL );
84 mp = monitor_entrypriv_create();
88 e->e_private = ( void * )mp;
90 mp->mp_flags = ms->mss_flags \
91 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
93 if ( monitor_cache_add( mi, e ) ) {
94 Debug( LDAP_DEBUG_ANY,
95 "monitor_subsys_time_init: "
96 "unable to add entry \"cn=Start,%s\"\n",
97 ms->mss_ndn.bv_val, 0, 0 );
107 BER_BVSTR( &bv, "cn=Current" );
108 e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &bv,
109 mi->mi_oc_monitoredObject, mi, NULL, NULL );
111 Debug( LDAP_DEBUG_ANY,
112 "monitor_subsys_time_init: "
113 "unable to create entry \"cn=Current,%s\"\n",
114 ms->mss_ndn.bv_val, 0, 0 );
117 attr_merge_normalize_one( e, mi->mi_ad_monitorTimestamp,
118 &mi->mi_startTime, NULL );
120 mp = monitor_entrypriv_create();
124 e->e_private = ( void * )mp;
126 mp->mp_flags = ms->mss_flags \
127 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
129 if ( monitor_cache_add( mi, e ) ) {
130 Debug( LDAP_DEBUG_ANY,
131 "monitor_subsys_time_init: "
132 "unable to add entry \"cn=Current,%s\"\n",
133 ms->mss_ndn.bv_val, 0, 0 );
140 monitor_cache_release( mi, e_time );
146 monitor_subsys_time_update(
151 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
152 static struct berval bv_current = BER_BVC( "cn=current" );
155 assert( mi != NULL );
158 dnRdn( &e->e_nname, &rdn );
160 if ( dn_match( &rdn, &bv_current ) ) {
165 char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
170 currtime = slap_get_time();
172 #ifndef HAVE_GMTIME_R
173 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
175 #ifdef HACK_LOCAL_TIME
176 # ifdef HAVE_LOCALTIME_R
177 tm = localtime_r( &currtime, &tm_buf );
179 tm = localtime( &currtime );
180 # endif /* HAVE_LOCALTIME_R */
181 lutil_localtime( tmbuf, sizeof( tmbuf ), tm, -timezone );
182 #else /* !HACK_LOCAL_TIME */
183 # ifdef HAVE_GMTIME_R
184 tm = gmtime_r( &currtime, &tm_buf );
186 tm = gmtime( &currtime );
187 # endif /* HAVE_GMTIME_R */
188 lutil_gentime( tmbuf, sizeof( tmbuf ), tm );
189 #endif /* !HACK_LOCAL_TIME */
190 #ifndef HAVE_GMTIME_R
191 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
194 len = strlen( tmbuf );
196 a = attr_find( e->e_attrs, mi->mi_ad_monitorTimestamp );
198 return rs->sr_err = LDAP_OTHER;
201 assert( len == a->a_vals[ 0 ].bv_len );
202 AC_MEMCPY( a->a_vals[ 0 ].bv_val, tmbuf, len );
204 /* FIXME: touch modifyTimestamp? */
207 return SLAP_CB_CONTINUE;