diff options
author | Mark Stapp <mjs@voltanet.io> | 2020-03-05 17:42:12 +0100 |
---|---|---|
committer | Mark Stapp <mjs@voltanet.io> | 2020-03-05 19:26:16 +0100 |
commit | a2700b5071e53a78be2f8098765dcca58c2b6ee5 (patch) | |
tree | e32654991ac297bd3917401ae429ee54da385e5e /bgpd | |
parent | Merge pull request #5890 from mjstapp/zapi_allow_label_num (diff) | |
download | frr-a2700b5071e53a78be2f8098765dcca58c2b6ee5.tar.xz frr-a2700b5071e53a78be2f8098765dcca58c2b6ee5.zip |
*: use gmtime_r, localtime_r exclusively
Stop using gmtime() or localtime() everywhere.
Signed-off-by: Mark Stapp <mjs@voltanet.io>
Diffstat (limited to 'bgpd')
-rw-r--r-- | bgpd/bgp_damp.c | 40 | ||||
-rw-r--r-- | bgpd/bgp_dump.c | 16 | ||||
-rw-r--r-- | bgpd/bgp_vty.c | 34 | ||||
-rw-r--r-- | bgpd/bgpd.c | 22 |
4 files changed, 58 insertions, 54 deletions
diff --git a/bgpd/bgp_damp.c b/bgpd/bgp_damp.c index b0fee079d..792f3cea7 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 298f9d021..c448b9894 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 62767a603..7b1ed61a1 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 96b307ee2..45076a3d7 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; |