From: Luke Howard Date: Sat, 6 Dec 2003 05:50:47 +0000 (+0000) Subject: Use gmtime_r()/localtime_r if HAVE_GMTIME_R/HAVE_LOCALTIME_R is defined (need to... X-Git-Tag: OPENLDAP_REL_ENG_2_1_MP~269 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e114ecbad5038641173a06dab8d9a7d6e534fd35;p=openldap Use gmtime_r()/localtime_r if HAVE_GMTIME_R/HAVE_LOCALTIME_R is defined (need to add autoconf check) --- diff --git a/servers/slapd/back-monitor/conn.c b/servers/slapd/back-monitor/conn.c index 4d72a0bf6e..0e022b9e9e 100644 --- a/servers/slapd/back-monitor/conn.c +++ b/servers/slapd/back-monitor/conn.c @@ -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, diff --git a/servers/slapd/back-monitor/init.c b/servers/slapd/back-monitor/init.c index 24e1499fb0..3ff3eb9510 100644 --- a/servers/slapd/back-monitor/init.c +++ b/servers/slapd/back-monitor/init.c @@ -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 ); diff --git a/servers/slapd/back-monitor/time.c b/servers/slapd/back-monitor/time.c index 5327f5206f..fa80b3f2e0 100644 --- a/servers/slapd/back-monitor/time.c +++ b/servers/slapd/back-monitor/time.c @@ -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 );