Skip to content
Snippets Groups Projects
Commit e114ecba authored by Luke Howard's avatar Luke Howard
Browse files

Use gmtime_r()/localtime_r if HAVE_GMTIME_R/HAVE_LOCALTIME_R is defined (need...

Use gmtime_r()/localtime_r if HAVE_GMTIME_R/HAVE_LOCALTIME_R is defined (need to add autoconf check)
parent 98481ec4
No related branches found
No related tags found
No related merge requests found
......@@ -295,23 +295,44 @@ conn_create(
char ctmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
struct tm *mtm;
char mtmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
#ifdef HAVE_GMTIME_R
struct tm tm_buf;
#endif /* HAVE_GMTIME_R */
assert( c != NULL );
assert( ep != NULL );
#ifndef HAVE_GMTIME_R
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
#endif
#ifdef HACK_LOCAL_TIME
# ifdef HAVE_LOCALTIME_R
ctm = localtime_r( &c->c_starttime, &tm_buf );
lutil_localtime( ctmbuf, sizeof( ctmbuf ), ctm, -timezone );
mtm = localtime_r( &c->c_activitytime, &tm_buf );
lutil_localtime( mtmbuf, sizeof( mtmbuf ), mtm, -timezone );
# else
ctm = localtime( &c->c_starttime );
lutil_localtime( ctmbuf, sizeof( ctmbuf ), ctm, -timezone );
mtm = localtime( &c->c_activitytime );
lutil_localtime( mtmbuf, sizeof( mtmbuf ), mtm, -timezone );
# endif /* HAVE_LOCALTIME_R */
#else /* !HACK_LOCAL_TIME */
# ifdef HAVE_GMTIME_R
ctm = gmtime_r( &c->c_starttime, &tm_buf );
lutil_gentime( ctmbuf, sizeof( ctmbuf ), ctm );
mtm = gmtime_r( &c->c_activitytime, &tm_buf );
lutil_gentime( mtmbuf, sizeof( mtmbuf ), mtm );
# else
ctm = gmtime( &c->c_starttime );
lutil_gentime( ctmbuf, sizeof( ctmbuf ), ctm );
mtm = gmtime( &c->c_activitytime );
lutil_gentime( mtmbuf, sizeof( mtmbuf ), mtm );
# endif /* HAVE_GMTIME_R */
#endif /* !HACK_LOCAL_TIME */
#ifndef HAVE_GMTIME_R
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
#endif
snprintf( buf, sizeof( buf ),
"dn: cn=" CONN_CN_PREFIX " %ld,%s\n"
......@@ -346,15 +367,27 @@ conn_create(
return( -1 );
}
#ifndef HAVE_GMTIME_R
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
#endif
#ifdef HAVE_GMTIME_R
ltm = gmtime_r( &c->c_starttime, &tm_buf );
#else
ltm = gmtime( &c->c_starttime );
#endif
lutil_gentime( buf2, sizeof( buf2 ), ltm );
#ifdef HAVE_GMTIME_R
ltm = gmtime_r( &c->c_activitytime, &tm_buf );
#else
ltm = gmtime( &c->c_activitytime );
#endif
lutil_gentime( buf3, sizeof( buf3 ), ltm );
#ifndef HAVE_GMTIME_R
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
#endif /* HAVE_GMTIME_R */
/* monitored info */
sprintf( buf,
......
......@@ -495,20 +495,35 @@ monitor_back_db_open(
};
struct tm *tms;
#ifdef HAVE_GMTIME_R
struct tm tm_buf;
#endif
static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
/*
* Start
*/
#ifndef HAVE_GMTIME_R
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
#endif
#ifdef HACK_LOCAL_TIME
# ifdef HAVE_LOCALTIME_R
tms = localtime_r( &starttime, &tm_buf );
# else
tms = localtime( &starttime );
# endif /* HAVE_LOCALTIME_R */
lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
#else /* !HACK_LOCAL_TIME */
# ifdef HAVE_GMTIME_R
tms = gmtime_r( &starttime, &tm_buf );
# else
tms = gmtime( &starttime );
# endif /* HAVE_GMTIME_R */
lutil_gentime( tmbuf, sizeof(tmbuf), tms );
#endif /* !HACK_LOCAL_TIME */
#ifndef HAVE_GMTIME_R
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
#endif
mi->mi_startTime.bv_val = tmbuf;
mi->mi_startTime.bv_len = strlen( tmbuf );
......
......@@ -235,6 +235,9 @@ monitor_subsys_time_update(
if ( strncmp( e->e_nname.bv_val, "cn=current",
sizeof("cn=current") - 1 ) == 0 ) {
struct tm *tm;
#ifdef HAVE_GMTIME_R
struct tm tm_buf;
#endif
char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
Attribute *a;
ber_len_t len;
......@@ -242,15 +245,27 @@ monitor_subsys_time_update(
currtime = slap_get_time();
#ifndef HAVE_GMTIME_R
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
#endif
#ifdef HACK_LOCAL_TIME
# ifdef HAVE_LOCALTIME_R
tm = localtime_r( &currtime, &tm_buf );
# else
tm = localtime( &currtime );
# endif /* HAVE_LOCALTIME_R */
lutil_localtime( tmbuf, sizeof( tmbuf ), tm, -timezone );
#else /* !HACK_LOCAL_TIME */
# ifdef HAVE_GMTIME_R
tm = gmtime_r( &currtime, &tm_buf );
# else
tm = gmtime( &currtime );
# endif /* HAVE_GMTIME_R */
lutil_gentime( tmbuf, sizeof( tmbuf ), tm );
#endif /* !HACK_LOCAL_TIME */
#ifndef HAVE_GMTIME_R
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
#endif
len = strlen( tmbuf );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment