]> git.sur5r.net Git - openldap/commitdiff
Use gmtime_r()/localtime_r if HAVE_GMTIME_R/HAVE_LOCALTIME_R is defined (need to...
authorLuke Howard <lukeh@openldap.org>
Sat, 6 Dec 2003 05:50:47 +0000 (05:50 +0000)
committerLuke Howard <lukeh@openldap.org>
Sat, 6 Dec 2003 05:50:47 +0000 (05:50 +0000)
servers/slapd/back-monitor/conn.c
servers/slapd/back-monitor/init.c
servers/slapd/back-monitor/time.c

index 4d72a0bf6e1175b0df23fe886937de46dae9dc3e..0e022b9e9e1183aea9942e6ad6a9a30ddec0617a 100644 (file)
@@ -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,
index 24e1499fb0dc10c6bbfcc1bd962c4ee7f00fbcf0..3ff3eb95107cba5e77f6d2ae430bf9fe3aa91294 100644 (file)
@@ -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 );
index 5327f5206fa559e8c895a955de49255a258cb177..fa80b3f2e0ef8d742e38bd1a3ade653d08da8775 100644 (file)
@@ -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 );