]> git.puffer.fish Git - mirror/frr.git/commitdiff
*: use gmtime_r, localtime_r exclusively 5916/head
authorMark Stapp <mjs@voltanet.io>
Thu, 5 Mar 2020 16:42:12 +0000 (11:42 -0500)
committerMark Stapp <mjs@voltanet.io>
Thu, 5 Mar 2020 18:26:16 +0000 (13:26 -0500)
Stop using gmtime() or localtime() everywhere.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
16 files changed:
bgpd/bgp_damp.c
bgpd/bgp_dump.c
bgpd/bgp_vty.c
bgpd/bgpd.c
isisd/isis_misc.c
isisd/isis_vty_fabricd.c
lib/bfd.c
lib/keychain.c
lib/log.c
ripd/rip_peer.c
ripd/ripd.c
ripngd/ripng_peer.c
ripngd/ripngd.c
vtysh/vtysh_main.c
zebra/zebra_vty.c
zebra/zserv.c

index b0fee079d16d29f479c157e6f2ec31fabd27869a..792f3cea70599d919c397473e987118987325766 100644 (file)
@@ -501,7 +501,7 @@ static const char *bgp_get_reuse_time(unsigned int penalty, char *buf,
                                      bool use_json, json_object *json)
 {
        time_t reuse_time = 0;
-       struct tm *tm = NULL;
+       struct tm tm;
        int time_store = 0;
 
        if (penalty > damp[afi][safi].reuse_limit) {
@@ -513,7 +513,7 @@ static const char *bgp_get_reuse_time(unsigned int penalty, char *buf,
                if (reuse_time > damp[afi][safi].max_suppress_time)
                        reuse_time = damp[afi][safi].max_suppress_time;
 
-               tm = gmtime(&reuse_time);
+               gmtime_r(&reuse_time, &tm);
        } else
                reuse_time = 0;
 
@@ -525,39 +525,39 @@ static const char *bgp_get_reuse_time(unsigned int penalty, char *buf,
                        snprintf(buf, len, "00:00:00");
        } else if (reuse_time < ONE_DAY_SECOND) {
                if (use_json) {
-                       time_store = (3600000 * tm->tm_hour)
-                                    + (60000 * tm->tm_min)
-                                    + (1000 * tm->tm_sec);
+                       time_store = (3600000 * tm.tm_hour)
+                                    + (60000 * tm.tm_min)
+                                    + (1000 * tm.tm_sec);
                        json_object_int_add(json, "reuseTimerMsecs",
                                            time_store);
                } else
-                       snprintf(buf, len, "%02d:%02d:%02d", tm->tm_hour,
-                                tm->tm_min, tm->tm_sec);
+                       snprintf(buf, len, "%02d:%02d:%02d", tm.tm_hour,
+                                tm.tm_min, tm.tm_sec);
        } else if (reuse_time < ONE_WEEK_SECOND) {
                if (use_json) {
-                       time_store = (86400000 * tm->tm_yday)
-                                    + (3600000 * tm->tm_hour)
-                                    + (60000 * tm->tm_min)
-                                    + (1000 * tm->tm_sec);
+                       time_store = (86400000 * tm.tm_yday)
+                                    + (3600000 * tm.tm_hour)
+                                    + (60000 * tm.tm_min)
+                                    + (1000 * tm.tm_sec);
                        json_object_int_add(json, "reuseTimerMsecs",
                                            time_store);
                } else
-                       snprintf(buf, len, "%dd%02dh%02dm", tm->tm_yday,
-                                tm->tm_hour, tm->tm_min);
+                       snprintf(buf, len, "%dd%02dh%02dm", tm.tm_yday,
+                                tm.tm_hour, tm.tm_min);
        } else {
                if (use_json) {
                        time_store =
-                               (604800000 * tm->tm_yday / 7)
+                               (604800000 * tm.tm_yday / 7)
                                + (86400000
-                                  * (tm->tm_yday - ((tm->tm_yday / 7) * 7)))
-                               + (3600000 * tm->tm_hour) + (60000 * tm->tm_min)
-                               + (1000 * tm->tm_sec);
+                                  * (tm.tm_yday - ((tm.tm_yday / 7) * 7)))
+                               + (3600000 * tm.tm_hour) + (60000 * tm.tm_min)
+                               + (1000 * tm.tm_sec);
                        json_object_int_add(json, "reuseTimerMsecs",
                                            time_store);
                } else
-                       snprintf(buf, len, "%02dw%dd%02dh", tm->tm_yday / 7,
-                                tm->tm_yday - ((tm->tm_yday / 7) * 7),
-                                tm->tm_hour);
+                       snprintf(buf, len, "%02dw%dd%02dh", tm.tm_yday / 7,
+                                tm.tm_yday - ((tm.tm_yday / 7) * 7),
+                                tm.tm_hour);
        }
 
        return buf;
index 298f9d0212b353ddb3eab347a52014bc23ce0529..c448b9894aeef3ba89a5ca0adad274ef375be9f0 100644 (file)
@@ -106,19 +106,19 @@ static FILE *bgp_dump_open_file(struct bgp_dump *bgp_dump)
 {
        int ret;
        time_t clock;
-       struct tm *tm;
+       struct tm tm;
        char fullpath[MAXPATHLEN];
        char realpath[MAXPATHLEN];
        mode_t oldumask;
 
        time(&clock);
-       tm = localtime(&clock);
+       localtime_r(&clock, &tm);
 
        if (bgp_dump->filename[0] != DIRECTORY_SEP) {
                sprintf(fullpath, "%s/%s", vty_get_cwd(), bgp_dump->filename);
-               ret = strftime(realpath, MAXPATHLEN, fullpath, tm);
+               ret = strftime(realpath, MAXPATHLEN, fullpath, &tm);
        } else
-               ret = strftime(realpath, MAXPATHLEN, bgp_dump->filename, tm);
+               ret = strftime(realpath, MAXPATHLEN, bgp_dump->filename, &tm);
 
        if (ret == 0) {
                flog_warn(EC_BGP_DUMP, "bgp_dump_open_file: strftime error");
@@ -147,7 +147,7 @@ static int bgp_dump_interval_add(struct bgp_dump *bgp_dump, int interval)
 {
        int secs_into_day;
        time_t t;
-       struct tm *tm;
+       struct tm tm;
 
        if (interval > 0) {
                /* Periodic dump every interval seconds */
@@ -158,9 +158,9 @@ static int bgp_dump_interval_add(struct bgp_dump *bgp_dump, int interval)
                         * midnight
                         */
                        (void)time(&t);
-                       tm = localtime(&t);
-                       secs_into_day = tm->tm_sec + 60 * tm->tm_min
-                                       + 60 * 60 * tm->tm_hour;
+                       localtime_r(&t, &tm);
+                       secs_into_day = tm.tm_sec + 60 * tm.tm_min
+                                       + 60 * 60 * tm.tm_hour;
                        interval = interval
                                   - secs_into_day % interval; /* always > 0 */
                }
index 62767a603c8869b0f57ff9aa185f5d141359e0cc..7b1ed61a1c0ef794adb782c2126f6ec7c7a360d9 100644 (file)
@@ -10657,28 +10657,31 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
 
                /* read timer */
                time_t uptime;
-               struct tm *tm;
+               struct tm tm;
 
                uptime = bgp_clock();
                uptime -= p->readtime;
-               tm = gmtime(&uptime);
+               gmtime_r(&uptime, &tm);
+
                json_object_int_add(json_neigh, "bgpTimerLastRead",
-                                   (tm->tm_sec * 1000) + (tm->tm_min * 60000)
-                                           + (tm->tm_hour * 3600000));
+                                   (tm.tm_sec * 1000) + (tm.tm_min * 60000)
+                                           + (tm.tm_hour * 3600000));
 
                uptime = bgp_clock();
                uptime -= p->last_write;
-               tm = gmtime(&uptime);
+               gmtime_r(&uptime, &tm);
+
                json_object_int_add(json_neigh, "bgpTimerLastWrite",
-                                   (tm->tm_sec * 1000) + (tm->tm_min * 60000)
-                                           + (tm->tm_hour * 3600000));
+                                   (tm.tm_sec * 1000) + (tm.tm_min * 60000)
+                                           + (tm.tm_hour * 3600000));
 
                uptime = bgp_clock();
                uptime -= p->update_time;
-               tm = gmtime(&uptime);
+               gmtime_r(&uptime, &tm);
+
                json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
-                                   (tm->tm_sec * 1000) + (tm->tm_min * 60000)
-                                           + (tm->tm_hour * 3600000));
+                                   (tm.tm_sec * 1000) + (tm.tm_min * 60000)
+                                           + (tm.tm_hour * 3600000));
 
                /* Configured timer values. */
                json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
@@ -11841,15 +11844,16 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
        } else {
                if (use_json) {
                        time_t uptime;
-                       struct tm *tm;
+                       struct tm tm;
 
                        uptime = bgp_clock();
                        uptime -= p->resettime;
-                       tm = gmtime(&uptime);
+                       gmtime_r(&uptime, &tm);
+
                        json_object_int_add(json_neigh, "lastResetTimerMsecs",
-                                           (tm->tm_sec * 1000)
-                                                   + (tm->tm_min * 60000)
-                                                   + (tm->tm_hour * 3600000));
+                                           (tm.tm_sec * 1000)
+                                                   + (tm.tm_min * 60000)
+                                                   + (tm.tm_hour * 3600000));
                        bgp_show_peer_reset(NULL, p, json_neigh, true);
                } else {
                        vty_out(vty, "  Last reset %s, ",
index 96b307ee21b31a235db842e37a06aad99b052310..45076a3d765b2845232566516dea596587654450 100644 (file)
@@ -6848,7 +6848,7 @@ char *peer_uptime(time_t uptime2, char *buf, size_t len, bool use_json,
                  json_object *json)
 {
        time_t uptime1, epoch_tbuf;
-       struct tm *tm;
+       struct tm tm;
 
        /* If there is no connection has been done before print `never'. */
        if (uptime2 == 0) {
@@ -6863,21 +6863,21 @@ char *peer_uptime(time_t uptime2, char *buf, size_t len, bool use_json,
        /* Get current time. */
        uptime1 = bgp_clock();
        uptime1 -= uptime2;
-       tm = gmtime(&uptime1);
+       gmtime_r(&uptime1, &tm);
 
        if (uptime1 < ONE_DAY_SECOND)
-               snprintf(buf, len, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
-                        tm->tm_sec);
+               snprintf(buf, len, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
+                        tm.tm_sec);
        else if (uptime1 < ONE_WEEK_SECOND)
-               snprintf(buf, len, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
-                        tm->tm_min);
+               snprintf(buf, len, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
+                        tm.tm_min);
        else if (uptime1 < ONE_YEAR_SECOND)
-               snprintf(buf, len, "%02dw%dd%02dh", tm->tm_yday / 7,
-                        tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour);
+               snprintf(buf, len, "%02dw%dd%02dh", tm.tm_yday / 7,
+                        tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour);
        else
-               snprintf(buf, len, "%02dy%02dw%dd", tm->tm_year - 70,
-                        tm->tm_yday / 7,
-                        tm->tm_yday - ((tm->tm_yday / 7) * 7));
+               snprintf(buf, len, "%02dy%02dw%dd", tm.tm_year - 70,
+                        tm.tm_yday / 7,
+                        tm.tm_yday - ((tm.tm_yday / 7) * 7));
 
        if (use_json) {
                epoch_tbuf = time(NULL) - uptime1;
index a7f491e87d8265e5ffeec2391a60b75edc86ed95..5fa33f55005bad5a83b5ee0ea2653947d23cb081 100644 (file)
@@ -562,19 +562,20 @@ void vty_multiline(struct vty *vty, const char *prefix, const char *format, ...)
 
 void vty_out_timestr(struct vty *vty, time_t uptime)
 {
-       struct tm *tm;
+       struct tm tm;
        time_t difftime = time(NULL);
        difftime -= uptime;
-       tm = gmtime(&difftime);
+
+       gmtime_r(&difftime, &tm);
 
        if (difftime < ONE_DAY_SECOND)
-               vty_out(vty, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
-                       tm->tm_sec);
+               vty_out(vty, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
+                       tm.tm_sec);
        else if (difftime < ONE_WEEK_SECOND)
-               vty_out(vty, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
-                       tm->tm_min);
+               vty_out(vty, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
+                       tm.tm_min);
        else
-               vty_out(vty, "%02dw%dd%02dh", tm->tm_yday / 7,
-                       tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour);
+               vty_out(vty, "%02dw%dd%02dh", tm.tm_yday / 7,
+                       tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour);
        vty_out(vty, " ago");
 }
index 24e5c519478c9a8384c4ed7dc079f1e5815c41be..88f7337a913e3e7bd46c7079fe6d3b6f175cf0e9 100644 (file)
@@ -129,18 +129,20 @@ static void lsp_print_flooding(struct vty *vty, struct isis_lsp *lsp)
                lsp->flooding_interface : "(null)");
 
        time_t uptime = time(NULL) - lsp->flooding_time;
-       struct tm *tm = gmtime(&uptime);
+       struct tm tm;
+
+       gmtime_r(&uptime, &tm);
 
        if (uptime < ONE_DAY_SECOND)
-               vty_out(vty, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
-                       tm->tm_sec);
+               vty_out(vty, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
+                       tm.tm_sec);
        else if (uptime < ONE_WEEK_SECOND)
-               vty_out(vty, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
-                       tm->tm_min);
+               vty_out(vty, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
+                       tm.tm_min);
        else
-               vty_out(vty, "%02dw%dd%02dh", tm->tm_yday / 7,
-                       tm->tm_yday - ((tm->tm_yday / 7) * 7),
-                       tm->tm_hour);
+               vty_out(vty, "%02dw%dd%02dh", tm.tm_yday / 7,
+                       tm.tm_yday - ((tm.tm_yday / 7) * 7),
+                       tm.tm_hour);
        vty_out(vty, " ago)\n");
 
        if (lsp->flooding_circuit_scoped) {
index 4e192422cdb5ffa49d160db0dc748a7ccefaa31d..a75618c069f8d5c27d8184d13ed56970bcf49e20 100644 (file)
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -328,7 +328,7 @@ static void bfd_last_update(time_t last_update, char *buf, size_t len)
 {
        time_t curr;
        time_t diff;
-       struct tm *tm;
+       struct tm tm;
        struct timeval tv;
 
        /* If no BFD satatus update has ever been received, print `never'. */
@@ -341,10 +341,10 @@ static void bfd_last_update(time_t last_update, char *buf, size_t len)
        monotime(&tv);
        curr = tv.tv_sec;
        diff = curr - last_update;
-       tm = gmtime(&diff);
+       gmtime_r(&diff, &tm);
 
-       snprintf(buf, len, "%d:%02d:%02d:%02d", tm->tm_yday, tm->tm_hour,
-                tm->tm_min, tm->tm_sec);
+       snprintf(buf, len, "%d:%02d:%02d:%02d", tm.tm_yday, tm.tm_hour,
+                tm.tm_min, tm.tm_sec);
 }
 
 /*
index fc9f0f9cfa95f811a2fef15ab96860babb8edd82..ea512a2699c62a6b8568e70548a0a5dde5261cd2 100644 (file)
@@ -967,12 +967,12 @@ static struct cmd_node keychain_key_node = {KEYCHAIN_KEY_NODE,
 
 static int keychain_strftime(char *buf, int bufsiz, time_t *time)
 {
-       struct tm *tm;
+       struct tm tm;
        size_t len;
 
-       tm = localtime(time);
+       localtime_r(time, &tm);
 
-       len = strftime(buf, bufsiz, "%T %b %d %Y", tm);
+       len = strftime(buf, bufsiz, "%T %b %d %Y", &tm);
 
        return len;
 }
index 5240eeaf726119003d69525e151a3ee2082966cf..2101e0225c4902bbb20e65a2e11370ae4b6e234e 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
@@ -220,11 +220,11 @@ size_t quagga_timestamp(int timestamp_precision, char *buf, size_t buflen)
 
        /* first, we update the cache if the time has changed */
        if (cache.last != clock.tv_sec) {
-               struct tm *tm;
+               struct tm tm;
                cache.last = clock.tv_sec;
-               tm = localtime(&cache.last);
+               localtime_r(&cache.last, &tm);
                cache.len = strftime(cache.buf, sizeof(cache.buf),
-                                    "%Y/%m/%d %H:%M:%S", tm);
+                                    "%Y/%m/%d %H:%M:%S", &tm);
        }
        /* note: it's not worth caching the subsecond part, because
           chances are that back-to-back calls are not sufficiently close
index 4ad7309c41c3b30a0a3bc86a5982f6abde72c7e7..55dafd7c1f845ef175fc113cbfb7cd1d00d952d0 100644 (file)
@@ -131,7 +131,7 @@ void rip_peer_bad_packet(struct rip *rip, struct sockaddr_in *from)
 static char *rip_peer_uptime(struct rip_peer *peer, char *buf, size_t len)
 {
        time_t uptime;
-       struct tm *tm;
+       struct tm tm;
 
        /* If there is no connection has been done before print `never'. */
        if (peer->uptime == 0) {
@@ -142,17 +142,17 @@ static char *rip_peer_uptime(struct rip_peer *peer, char *buf, size_t len)
        /* Get current time. */
        uptime = time(NULL);
        uptime -= peer->uptime;
-       tm = gmtime(&uptime);
+       gmtime_r(&uptime, &tm);
 
        if (uptime < ONE_DAY_SECOND)
-               snprintf(buf, len, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
-                        tm->tm_sec);
+               snprintf(buf, len, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
+                        tm.tm_sec);
        else if (uptime < ONE_WEEK_SECOND)
-               snprintf(buf, len, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
-                        tm->tm_min);
+               snprintf(buf, len, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
+                        tm.tm_min);
        else
-               snprintf(buf, len, "%02dw%dd%02dh", tm->tm_yday / 7,
-                        tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour);
+               snprintf(buf, len, "%02dw%dd%02dh", tm.tm_yday / 7,
+                        tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour);
        return buf;
 }
 
index 5ccefac1788d1a2277a081b5c8a64f5cbf83adc8..5009b788ffdb543455a43a04ae905fdcc4201681 100644 (file)
@@ -3020,20 +3020,20 @@ void rip_ecmp_disable(struct rip *rip)
 static void rip_vty_out_uptime(struct vty *vty, struct rip_info *rinfo)
 {
        time_t clock;
-       struct tm *tm;
+       struct tm tm;
 #define TIME_BUF 25
        char timebuf[TIME_BUF];
        struct thread *thread;
 
        if ((thread = rinfo->t_timeout) != NULL) {
                clock = thread_timer_remain_second(thread);
-               tm = gmtime(&clock);
-               strftime(timebuf, TIME_BUF, "%M:%S", tm);
+               gmtime_r(&clock, &tm);
+               strftime(timebuf, TIME_BUF, "%M:%S", &tm);
                vty_out(vty, "%5s", timebuf);
        } else if ((thread = rinfo->t_garbage_collect) != NULL) {
                clock = thread_timer_remain_second(thread);
-               tm = gmtime(&clock);
-               strftime(timebuf, TIME_BUF, "%M:%S", tm);
+               gmtime_r(&clock, &tm);
+               strftime(timebuf, TIME_BUF, "%M:%S", &tm);
                vty_out(vty, "%5s", timebuf);
        }
 }
index 109524e2129091f51c5977f07bffaadcd4be65f7..c038bfccf021794fb4d3e29ee0128d72379cfcba 100644 (file)
@@ -141,7 +141,7 @@ void ripng_peer_bad_packet(struct ripng *ripng, struct sockaddr_in6 *from)
 static char *ripng_peer_uptime(struct ripng_peer *peer, char *buf, size_t len)
 {
        time_t uptime;
-       struct tm *tm;
+       struct tm tm;
 
        /* If there is no connection has been done before print `never'. */
        if (peer->uptime == 0) {
@@ -152,17 +152,17 @@ static char *ripng_peer_uptime(struct ripng_peer *peer, char *buf, size_t len)
        /* Get current time. */
        uptime = time(NULL);
        uptime -= peer->uptime;
-       tm = gmtime(&uptime);
+       gmtime_r(&uptime, &tm);
 
        if (uptime < ONE_DAY_SECOND)
-               snprintf(buf, len, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
-                        tm->tm_sec);
+               snprintf(buf, len, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
+                        tm.tm_sec);
        else if (uptime < ONE_WEEK_SECOND)
-               snprintf(buf, len, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
-                        tm->tm_min);
+               snprintf(buf, len, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
+                        tm.tm_min);
        else
-               snprintf(buf, len, "%02dw%dd%02dh", tm->tm_yday / 7,
-                        tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour);
+               snprintf(buf, len, "%02dw%dd%02dh", tm.tm_yday / 7,
+                        tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour);
        return buf;
 }
 
index f8d7dc968b8462ec2627e7778ecaa33008690d2c..b583df4deb83f8e2f6640575784043791e262d6c 100644 (file)
@@ -1991,20 +1991,20 @@ void ripng_event(struct ripng *ripng, enum ripng_event event, int sock)
 static void ripng_vty_out_uptime(struct vty *vty, struct ripng_info *rinfo)
 {
        time_t clock;
-       struct tm *tm;
+       struct tm tm;
 #define TIME_BUF 25
        char timebuf[TIME_BUF];
        struct thread *thread;
 
        if ((thread = rinfo->t_timeout) != NULL) {
                clock = thread_timer_remain_second(thread);
-               tm = gmtime(&clock);
-               strftime(timebuf, TIME_BUF, "%M:%S", tm);
+               gmtime_r(&clock, &tm);
+               strftime(timebuf, TIME_BUF, "%M:%S", &tm);
                vty_out(vty, "%5s", timebuf);
        } else if ((thread = rinfo->t_garbage_collect) != NULL) {
                clock = thread_timer_remain_second(thread);
-               tm = gmtime(&clock);
-               strftime(timebuf, TIME_BUF, "%M:%S", tm);
+               gmtime_r(&clock, &tm);
+               strftime(timebuf, TIME_BUF, "%M:%S", &tm);
                vty_out(vty, "%5s", timebuf);
        }
 }
index 59512742572d2e2b72e67091a4b6bf55ddd838dd..cc8c536c741eb572a9d258978f6ec82eb1602902 100644 (file)
@@ -229,14 +229,15 @@ static char *vtysh_rl_gets(void)
 static void log_it(const char *line)
 {
        time_t t = time(NULL);
-       struct tm *tmp = localtime(&t);
+       struct tm tmp;
        const char *user = getenv("USER");
        char tod[64];
 
+       localtime_r(&t, &tmp);
        if (!user)
                user = "boot";
 
-       strftime(tod, sizeof tod, "%Y%m%d-%H:%M.%S", tmp);
+       strftime(tod, sizeof tod, "%Y%m%d-%H:%M.%S", &tmp);
 
        fprintf(logfile, "%s:%s %s\n", tod, user, line);
 }
index 8c719f4b6a02a53fc22d44d159c4d946c1dc2c84..789871a80c96f3f5674ccc10d36690d27cd7025f 100644 (file)
@@ -241,24 +241,24 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn,
                vty_out(vty, "\n");
 
                time_t uptime;
-               struct tm *tm;
+               struct tm tm;
 
                uptime = monotime(NULL);
                uptime -= re->uptime;
-               tm = gmtime(&uptime);
+               gmtime_r(&uptime, &tm);
 
                vty_out(vty, "  Last update ");
 
                if (uptime < ONE_DAY_SECOND)
-                       vty_out(vty, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
-                               tm->tm_sec);
+                       vty_out(vty, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
+                               tm.tm_sec);
                else if (uptime < ONE_WEEK_SECOND)
-                       vty_out(vty, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
-                               tm->tm_min);
+                       vty_out(vty, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
+                               tm.tm_min);
                else
-                       vty_out(vty, "%02dw%dd%02dh", tm->tm_yday / 7,
-                               tm->tm_yday - ((tm->tm_yday / 7) * 7),
-                               tm->tm_hour);
+                       vty_out(vty, "%02dw%dd%02dh", tm.tm_yday / 7,
+                               tm.tm_yday - ((tm.tm_yday / 7) * 7),
+                               tm.tm_hour);
                vty_out(vty, " ago\n");
 
                if (show_ng)
@@ -402,14 +402,14 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
        json_object *json_route = NULL;
        json_object *json_labels = NULL;
        time_t uptime;
-       struct tm *tm;
+       struct tm tm;
        struct vrf *vrf = NULL;
        rib_dest_t *dest = rib_dest_from_rnode(rn);
        struct nexthop_group *nhg;
 
        uptime = monotime(NULL);
        uptime -= re->uptime;
-       tm = gmtime(&uptime);
+       gmtime_r(&uptime, &tm);
 
        /* If showing fib information, use the fib view of the
         * nexthops.
@@ -475,15 +475,15 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
                                    nexthop_group_active_nexthop_num(
                                            &(re->nhe->nhg)));
                if (uptime < ONE_DAY_SECOND)
-                       sprintf(buf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
-                               tm->tm_sec);
+                       sprintf(buf, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
+                               tm.tm_sec);
                else if (uptime < ONE_WEEK_SECOND)
-                       sprintf(buf, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
-                               tm->tm_min);
+                       sprintf(buf, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
+                               tm.tm_min);
                else
-                       sprintf(buf, "%02dw%dd%02dh", tm->tm_yday / 7,
-                               tm->tm_yday - ((tm->tm_yday / 7) * 7),
-                               tm->tm_hour);
+                       sprintf(buf, "%02dw%dd%02dh", tm.tm_yday / 7,
+                               tm.tm_yday - ((tm.tm_yday / 7) * 7),
+                               tm.tm_hour);
 
                json_object_string_add(json_route, "uptime", buf);
 
@@ -775,15 +775,15 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
                }
 
                if (uptime < ONE_DAY_SECOND)
-                       vty_out(vty, ", %02d:%02d:%02d", tm->tm_hour,
-                               tm->tm_min, tm->tm_sec);
+                       vty_out(vty, ", %02d:%02d:%02d", tm.tm_hour,
+                               tm.tm_min, tm.tm_sec);
                else if (uptime < ONE_WEEK_SECOND)
-                       vty_out(vty, ", %dd%02dh%02dm", tm->tm_yday,
-                               tm->tm_hour, tm->tm_min);
+                       vty_out(vty, ", %dd%02dh%02dm", tm.tm_yday,
+                               tm.tm_hour, tm.tm_min);
                else
-                       vty_out(vty, ", %02dw%dd%02dh", tm->tm_yday / 7,
-                               tm->tm_yday - ((tm->tm_yday / 7) * 7),
-                               tm->tm_hour);
+                       vty_out(vty, ", %02dw%dd%02dh", tm.tm_yday / 7,
+                               tm.tm_yday - ((tm.tm_yday / 7) * 7),
+                               tm.tm_hour);
                vty_out(vty, "\n");
        }
 }
index 2a5352a1da26e063a00748c07cb77bab5fd24c4b..6a62a97aeb913f27cd384f0c830a91ac7266f37e 100644 (file)
@@ -858,7 +858,7 @@ void zserv_event(struct zserv *client, enum zserv_event event)
 #define ZEBRA_TIME_BUF 32
 static char *zserv_time_buf(time_t *time1, char *buf, int buflen)
 {
-       struct tm *tm;
+       struct tm tm;
        time_t now;
 
        assert(buf != NULL);
@@ -872,17 +872,17 @@ static char *zserv_time_buf(time_t *time1, char *buf, int buflen)
 
        now = monotime(NULL);
        now -= *time1;
-       tm = gmtime(&now);
+       gmtime_r(&now, &tm);
 
        if (now < ONE_DAY_SECOND)
-               snprintf(buf, buflen, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
-                        tm->tm_sec);
+               snprintf(buf, buflen, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
+                        tm.tm_sec);
        else if (now < ONE_WEEK_SECOND)
-               snprintf(buf, buflen, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
-                        tm->tm_min);
+               snprintf(buf, buflen, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
+                        tm.tm_min);
        else
-               snprintf(buf, buflen, "%02dw%dd%02dh", tm->tm_yday / 7,
-                        tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour);
+               snprintf(buf, buflen, "%02dw%dd%02dh", tm.tm_yday / 7,
+                        tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour);
        return buf;
 }
 
@@ -1001,7 +1001,7 @@ static void zebra_show_stale_client_detail(struct vty *vty,
                                           struct zserv *client)
 {
        char buf[PREFIX2STR_BUFFER];
-       struct tm *tm;
+       struct tm tm;
        struct timeval tv;
        time_t uptime;
        struct client_gr_info *info = NULL;
@@ -1030,22 +1030,23 @@ static void zebra_show_stale_client_detail(struct vty *vty,
                                s = (struct zserv *)(info->stale_client_ptr);
                                uptime = monotime(&tv);
                                uptime -= s->restart_time;
-                               tm = gmtime(&uptime);
+                               gmtime_r(&uptime, &tm);
+
                                vty_out(vty, "Last restart time : ");
                                if (uptime < ONE_DAY_SECOND)
                                        vty_out(vty, "%02d:%02d:%02d",
-                                               tm->tm_hour, tm->tm_min,
-                                               tm->tm_sec);
+                                               tm.tm_hour, tm.tm_min,
+                                               tm.tm_sec);
                                else if (uptime < ONE_WEEK_SECOND)
                                        vty_out(vty, "%dd%02dh%02dm",
-                                               tm->tm_yday, tm->tm_hour,
-                                               tm->tm_min);
+                                               tm.tm_yday, tm.tm_hour,
+                                               tm.tm_min);
                                else
                                        vty_out(vty, "%02dw%dd%02dh",
-                                               tm->tm_yday / 7,
-                                               tm->tm_yday - ((tm->tm_yday / 7)
+                                               tm.tm_yday / 7,
+                                               tm.tm_yday - ((tm.tm_yday / 7)
                                                               * 7),
-                                               tm->tm_hour);
+                                               tm.tm_hour);
                                vty_out(vty, "  ago\n");
 
                                vty_out(vty, "Stalepath removal time: %d sec\n",