From: Mark Stapp Date: Thu, 5 Mar 2020 16:42:12 +0000 (-0500) Subject: *: use gmtime_r, localtime_r exclusively X-Git-Tag: base_7.4~287^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=refs%2Fpull%2F5916%2Fhead;p=mirror%2Ffrr.git *: use gmtime_r, localtime_r exclusively Stop using gmtime() or localtime() everywhere. Signed-off-by: Mark Stapp --- diff --git a/bgpd/bgp_damp.c b/bgpd/bgp_damp.c index b0fee079d1..792f3cea70 100644 --- a/bgpd/bgp_damp.c +++ b/bgpd/bgp_damp.c @@ -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; diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c index 298f9d0212..c448b9894a 100644 --- a/bgpd/bgp_dump.c +++ b/bgpd/bgp_dump.c @@ -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 */ } diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 62767a603c..7b1ed61a1c 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -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, ", diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 96b307ee21..45076a3d76 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -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; diff --git a/isisd/isis_misc.c b/isisd/isis_misc.c index a7f491e87d..5fa33f5500 100644 --- a/isisd/isis_misc.c +++ b/isisd/isis_misc.c @@ -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"); } diff --git a/isisd/isis_vty_fabricd.c b/isisd/isis_vty_fabricd.c index 24e5c51947..88f7337a91 100644 --- a/isisd/isis_vty_fabricd.c +++ b/isisd/isis_vty_fabricd.c @@ -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) { diff --git a/lib/bfd.c b/lib/bfd.c index 4e192422cd..a75618c069 100644 --- 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); } /* diff --git a/lib/keychain.c b/lib/keychain.c index fc9f0f9cfa..ea512a2699 100644 --- a/lib/keychain.c +++ b/lib/keychain.c @@ -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; } diff --git a/lib/log.c b/lib/log.c index 5240eeaf72..2101e0225c 100644 --- 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 diff --git a/ripd/rip_peer.c b/ripd/rip_peer.c index 4ad7309c41..55dafd7c1f 100644 --- a/ripd/rip_peer.c +++ b/ripd/rip_peer.c @@ -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; } diff --git a/ripd/ripd.c b/ripd/ripd.c index 5ccefac178..5009b788ff 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -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); } } diff --git a/ripngd/ripng_peer.c b/ripngd/ripng_peer.c index 109524e212..c038bfccf0 100644 --- a/ripngd/ripng_peer.c +++ b/ripngd/ripng_peer.c @@ -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; } diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index f8d7dc968b..b583df4deb 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -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); } } diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index 5951274257..cc8c536c74 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -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); } diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 8c719f4b6a..789871a80c 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -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"); } } diff --git a/zebra/zserv.c b/zebra/zserv.c index 2a5352a1da..6a62a97aeb 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -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",