*: use gmtime_r, localtime_r exclusively

Stop using gmtime() or localtime() everywhere.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
This commit is contained in:
Mark Stapp 2020-03-05 11:42:12 -05:00
parent 1e273766cb
commit a2700b5071
16 changed files with 159 additions and 150 deletions

View 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;

View 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 */
}

View 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, ",

View 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;

View 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");
}

View 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) {

View file

@ -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);
}
/*

View 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;
}

View file

@ -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

View 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;
}

View 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);
}
}

View 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;
}

View 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);
}
}

View 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);
}

View 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");
}
}

View 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",