forked from Mirror/frr
*: 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:
parent
1e273766cb
commit
a2700b5071
|
@ -501,7 +501,7 @@ static const char *bgp_get_reuse_time(unsigned int penalty, char *buf,
|
||||||
bool use_json, json_object *json)
|
bool use_json, json_object *json)
|
||||||
{
|
{
|
||||||
time_t reuse_time = 0;
|
time_t reuse_time = 0;
|
||||||
struct tm *tm = NULL;
|
struct tm tm;
|
||||||
int time_store = 0;
|
int time_store = 0;
|
||||||
|
|
||||||
if (penalty > damp[afi][safi].reuse_limit) {
|
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)
|
if (reuse_time > damp[afi][safi].max_suppress_time)
|
||||||
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
|
} else
|
||||||
reuse_time = 0;
|
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");
|
snprintf(buf, len, "00:00:00");
|
||||||
} else if (reuse_time < ONE_DAY_SECOND) {
|
} else if (reuse_time < ONE_DAY_SECOND) {
|
||||||
if (use_json) {
|
if (use_json) {
|
||||||
time_store = (3600000 * tm->tm_hour)
|
time_store = (3600000 * tm.tm_hour)
|
||||||
+ (60000 * tm->tm_min)
|
+ (60000 * tm.tm_min)
|
||||||
+ (1000 * tm->tm_sec);
|
+ (1000 * tm.tm_sec);
|
||||||
json_object_int_add(json, "reuseTimerMsecs",
|
json_object_int_add(json, "reuseTimerMsecs",
|
||||||
time_store);
|
time_store);
|
||||||
} else
|
} else
|
||||||
snprintf(buf, len, "%02d:%02d:%02d", tm->tm_hour,
|
snprintf(buf, len, "%02d:%02d:%02d", tm.tm_hour,
|
||||||
tm->tm_min, tm->tm_sec);
|
tm.tm_min, tm.tm_sec);
|
||||||
} else if (reuse_time < ONE_WEEK_SECOND) {
|
} else if (reuse_time < ONE_WEEK_SECOND) {
|
||||||
if (use_json) {
|
if (use_json) {
|
||||||
time_store = (86400000 * tm->tm_yday)
|
time_store = (86400000 * tm.tm_yday)
|
||||||
+ (3600000 * tm->tm_hour)
|
+ (3600000 * tm.tm_hour)
|
||||||
+ (60000 * tm->tm_min)
|
+ (60000 * tm.tm_min)
|
||||||
+ (1000 * tm->tm_sec);
|
+ (1000 * tm.tm_sec);
|
||||||
json_object_int_add(json, "reuseTimerMsecs",
|
json_object_int_add(json, "reuseTimerMsecs",
|
||||||
time_store);
|
time_store);
|
||||||
} else
|
} else
|
||||||
snprintf(buf, len, "%dd%02dh%02dm", tm->tm_yday,
|
snprintf(buf, len, "%dd%02dh%02dm", tm.tm_yday,
|
||||||
tm->tm_hour, tm->tm_min);
|
tm.tm_hour, tm.tm_min);
|
||||||
} else {
|
} else {
|
||||||
if (use_json) {
|
if (use_json) {
|
||||||
time_store =
|
time_store =
|
||||||
(604800000 * tm->tm_yday / 7)
|
(604800000 * tm.tm_yday / 7)
|
||||||
+ (86400000
|
+ (86400000
|
||||||
* (tm->tm_yday - ((tm->tm_yday / 7) * 7)))
|
* (tm.tm_yday - ((tm.tm_yday / 7) * 7)))
|
||||||
+ (3600000 * tm->tm_hour) + (60000 * tm->tm_min)
|
+ (3600000 * tm.tm_hour) + (60000 * tm.tm_min)
|
||||||
+ (1000 * tm->tm_sec);
|
+ (1000 * tm.tm_sec);
|
||||||
json_object_int_add(json, "reuseTimerMsecs",
|
json_object_int_add(json, "reuseTimerMsecs",
|
||||||
time_store);
|
time_store);
|
||||||
} else
|
} else
|
||||||
snprintf(buf, len, "%02dw%dd%02dh", tm->tm_yday / 7,
|
snprintf(buf, len, "%02dw%dd%02dh", tm.tm_yday / 7,
|
||||||
tm->tm_yday - ((tm->tm_yday / 7) * 7),
|
tm.tm_yday - ((tm.tm_yday / 7) * 7),
|
||||||
tm->tm_hour);
|
tm.tm_hour);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
|
|
|
@ -106,19 +106,19 @@ static FILE *bgp_dump_open_file(struct bgp_dump *bgp_dump)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
time_t clock;
|
time_t clock;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
char fullpath[MAXPATHLEN];
|
char fullpath[MAXPATHLEN];
|
||||||
char realpath[MAXPATHLEN];
|
char realpath[MAXPATHLEN];
|
||||||
mode_t oldumask;
|
mode_t oldumask;
|
||||||
|
|
||||||
time(&clock);
|
time(&clock);
|
||||||
tm = localtime(&clock);
|
localtime_r(&clock, &tm);
|
||||||
|
|
||||||
if (bgp_dump->filename[0] != DIRECTORY_SEP) {
|
if (bgp_dump->filename[0] != DIRECTORY_SEP) {
|
||||||
sprintf(fullpath, "%s/%s", vty_get_cwd(), bgp_dump->filename);
|
sprintf(fullpath, "%s/%s", vty_get_cwd(), bgp_dump->filename);
|
||||||
ret = strftime(realpath, MAXPATHLEN, fullpath, tm);
|
ret = strftime(realpath, MAXPATHLEN, fullpath, &tm);
|
||||||
} else
|
} else
|
||||||
ret = strftime(realpath, MAXPATHLEN, bgp_dump->filename, tm);
|
ret = strftime(realpath, MAXPATHLEN, bgp_dump->filename, &tm);
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
flog_warn(EC_BGP_DUMP, "bgp_dump_open_file: strftime error");
|
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;
|
int secs_into_day;
|
||||||
time_t t;
|
time_t t;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
|
|
||||||
if (interval > 0) {
|
if (interval > 0) {
|
||||||
/* Periodic dump every interval seconds */
|
/* Periodic dump every interval seconds */
|
||||||
|
@ -158,9 +158,9 @@ static int bgp_dump_interval_add(struct bgp_dump *bgp_dump, int interval)
|
||||||
* midnight
|
* midnight
|
||||||
*/
|
*/
|
||||||
(void)time(&t);
|
(void)time(&t);
|
||||||
tm = localtime(&t);
|
localtime_r(&t, &tm);
|
||||||
secs_into_day = tm->tm_sec + 60 * tm->tm_min
|
secs_into_day = tm.tm_sec + 60 * tm.tm_min
|
||||||
+ 60 * 60 * tm->tm_hour;
|
+ 60 * 60 * tm.tm_hour;
|
||||||
interval = interval
|
interval = interval
|
||||||
- secs_into_day % interval; /* always > 0 */
|
- secs_into_day % interval; /* always > 0 */
|
||||||
}
|
}
|
||||||
|
|
|
@ -10657,28 +10657,31 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
|
||||||
|
|
||||||
/* read timer */
|
/* read timer */
|
||||||
time_t uptime;
|
time_t uptime;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
|
|
||||||
uptime = bgp_clock();
|
uptime = bgp_clock();
|
||||||
uptime -= p->readtime;
|
uptime -= p->readtime;
|
||||||
tm = gmtime(&uptime);
|
gmtime_r(&uptime, &tm);
|
||||||
|
|
||||||
json_object_int_add(json_neigh, "bgpTimerLastRead",
|
json_object_int_add(json_neigh, "bgpTimerLastRead",
|
||||||
(tm->tm_sec * 1000) + (tm->tm_min * 60000)
|
(tm.tm_sec * 1000) + (tm.tm_min * 60000)
|
||||||
+ (tm->tm_hour * 3600000));
|
+ (tm.tm_hour * 3600000));
|
||||||
|
|
||||||
uptime = bgp_clock();
|
uptime = bgp_clock();
|
||||||
uptime -= p->last_write;
|
uptime -= p->last_write;
|
||||||
tm = gmtime(&uptime);
|
gmtime_r(&uptime, &tm);
|
||||||
|
|
||||||
json_object_int_add(json_neigh, "bgpTimerLastWrite",
|
json_object_int_add(json_neigh, "bgpTimerLastWrite",
|
||||||
(tm->tm_sec * 1000) + (tm->tm_min * 60000)
|
(tm.tm_sec * 1000) + (tm.tm_min * 60000)
|
||||||
+ (tm->tm_hour * 3600000));
|
+ (tm.tm_hour * 3600000));
|
||||||
|
|
||||||
uptime = bgp_clock();
|
uptime = bgp_clock();
|
||||||
uptime -= p->update_time;
|
uptime -= p->update_time;
|
||||||
tm = gmtime(&uptime);
|
gmtime_r(&uptime, &tm);
|
||||||
|
|
||||||
json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
|
json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
|
||||||
(tm->tm_sec * 1000) + (tm->tm_min * 60000)
|
(tm.tm_sec * 1000) + (tm.tm_min * 60000)
|
||||||
+ (tm->tm_hour * 3600000));
|
+ (tm.tm_hour * 3600000));
|
||||||
|
|
||||||
/* Configured timer values. */
|
/* Configured timer values. */
|
||||||
json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
|
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 {
|
} else {
|
||||||
if (use_json) {
|
if (use_json) {
|
||||||
time_t uptime;
|
time_t uptime;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
|
|
||||||
uptime = bgp_clock();
|
uptime = bgp_clock();
|
||||||
uptime -= p->resettime;
|
uptime -= p->resettime;
|
||||||
tm = gmtime(&uptime);
|
gmtime_r(&uptime, &tm);
|
||||||
|
|
||||||
json_object_int_add(json_neigh, "lastResetTimerMsecs",
|
json_object_int_add(json_neigh, "lastResetTimerMsecs",
|
||||||
(tm->tm_sec * 1000)
|
(tm.tm_sec * 1000)
|
||||||
+ (tm->tm_min * 60000)
|
+ (tm.tm_min * 60000)
|
||||||
+ (tm->tm_hour * 3600000));
|
+ (tm.tm_hour * 3600000));
|
||||||
bgp_show_peer_reset(NULL, p, json_neigh, true);
|
bgp_show_peer_reset(NULL, p, json_neigh, true);
|
||||||
} else {
|
} else {
|
||||||
vty_out(vty, " Last reset %s, ",
|
vty_out(vty, " Last reset %s, ",
|
||||||
|
|
22
bgpd/bgpd.c
22
bgpd/bgpd.c
|
@ -6848,7 +6848,7 @@ char *peer_uptime(time_t uptime2, char *buf, size_t len, bool use_json,
|
||||||
json_object *json)
|
json_object *json)
|
||||||
{
|
{
|
||||||
time_t uptime1, epoch_tbuf;
|
time_t uptime1, epoch_tbuf;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
|
|
||||||
/* If there is no connection has been done before print `never'. */
|
/* If there is no connection has been done before print `never'. */
|
||||||
if (uptime2 == 0) {
|
if (uptime2 == 0) {
|
||||||
|
@ -6863,21 +6863,21 @@ char *peer_uptime(time_t uptime2, char *buf, size_t len, bool use_json,
|
||||||
/* Get current time. */
|
/* Get current time. */
|
||||||
uptime1 = bgp_clock();
|
uptime1 = bgp_clock();
|
||||||
uptime1 -= uptime2;
|
uptime1 -= uptime2;
|
||||||
tm = gmtime(&uptime1);
|
gmtime_r(&uptime1, &tm);
|
||||||
|
|
||||||
if (uptime1 < ONE_DAY_SECOND)
|
if (uptime1 < ONE_DAY_SECOND)
|
||||||
snprintf(buf, len, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
|
snprintf(buf, len, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
|
||||||
tm->tm_sec);
|
tm.tm_sec);
|
||||||
else if (uptime1 < ONE_WEEK_SECOND)
|
else if (uptime1 < ONE_WEEK_SECOND)
|
||||||
snprintf(buf, len, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
|
snprintf(buf, len, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
|
||||||
tm->tm_min);
|
tm.tm_min);
|
||||||
else if (uptime1 < ONE_YEAR_SECOND)
|
else if (uptime1 < ONE_YEAR_SECOND)
|
||||||
snprintf(buf, len, "%02dw%dd%02dh", tm->tm_yday / 7,
|
snprintf(buf, len, "%02dw%dd%02dh", tm.tm_yday / 7,
|
||||||
tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour);
|
tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour);
|
||||||
else
|
else
|
||||||
snprintf(buf, len, "%02dy%02dw%dd", tm->tm_year - 70,
|
snprintf(buf, len, "%02dy%02dw%dd", tm.tm_year - 70,
|
||||||
tm->tm_yday / 7,
|
tm.tm_yday / 7,
|
||||||
tm->tm_yday - ((tm->tm_yday / 7) * 7));
|
tm.tm_yday - ((tm.tm_yday / 7) * 7));
|
||||||
|
|
||||||
if (use_json) {
|
if (use_json) {
|
||||||
epoch_tbuf = time(NULL) - uptime1;
|
epoch_tbuf = time(NULL) - uptime1;
|
||||||
|
|
|
@ -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)
|
void vty_out_timestr(struct vty *vty, time_t uptime)
|
||||||
{
|
{
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
time_t difftime = time(NULL);
|
time_t difftime = time(NULL);
|
||||||
difftime -= uptime;
|
difftime -= uptime;
|
||||||
tm = gmtime(&difftime);
|
|
||||||
|
gmtime_r(&difftime, &tm);
|
||||||
|
|
||||||
if (difftime < ONE_DAY_SECOND)
|
if (difftime < ONE_DAY_SECOND)
|
||||||
vty_out(vty, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
|
vty_out(vty, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
|
||||||
tm->tm_sec);
|
tm.tm_sec);
|
||||||
else if (difftime < ONE_WEEK_SECOND)
|
else if (difftime < ONE_WEEK_SECOND)
|
||||||
vty_out(vty, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
|
vty_out(vty, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
|
||||||
tm->tm_min);
|
tm.tm_min);
|
||||||
else
|
else
|
||||||
vty_out(vty, "%02dw%dd%02dh", tm->tm_yday / 7,
|
vty_out(vty, "%02dw%dd%02dh", tm.tm_yday / 7,
|
||||||
tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour);
|
tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour);
|
||||||
vty_out(vty, " ago");
|
vty_out(vty, " ago");
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,18 +129,20 @@ static void lsp_print_flooding(struct vty *vty, struct isis_lsp *lsp)
|
||||||
lsp->flooding_interface : "(null)");
|
lsp->flooding_interface : "(null)");
|
||||||
|
|
||||||
time_t uptime = time(NULL) - lsp->flooding_time;
|
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)
|
if (uptime < ONE_DAY_SECOND)
|
||||||
vty_out(vty, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
|
vty_out(vty, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
|
||||||
tm->tm_sec);
|
tm.tm_sec);
|
||||||
else if (uptime < ONE_WEEK_SECOND)
|
else if (uptime < ONE_WEEK_SECOND)
|
||||||
vty_out(vty, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
|
vty_out(vty, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
|
||||||
tm->tm_min);
|
tm.tm_min);
|
||||||
else
|
else
|
||||||
vty_out(vty, "%02dw%dd%02dh", tm->tm_yday / 7,
|
vty_out(vty, "%02dw%dd%02dh", tm.tm_yday / 7,
|
||||||
tm->tm_yday - ((tm->tm_yday / 7) * 7),
|
tm.tm_yday - ((tm.tm_yday / 7) * 7),
|
||||||
tm->tm_hour);
|
tm.tm_hour);
|
||||||
vty_out(vty, " ago)\n");
|
vty_out(vty, " ago)\n");
|
||||||
|
|
||||||
if (lsp->flooding_circuit_scoped) {
|
if (lsp->flooding_circuit_scoped) {
|
||||||
|
|
|
@ -328,7 +328,7 @@ static void bfd_last_update(time_t last_update, char *buf, size_t len)
|
||||||
{
|
{
|
||||||
time_t curr;
|
time_t curr;
|
||||||
time_t diff;
|
time_t diff;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
/* If no BFD satatus update has ever been received, print `never'. */
|
/* 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);
|
monotime(&tv);
|
||||||
curr = tv.tv_sec;
|
curr = tv.tv_sec;
|
||||||
diff = curr - last_update;
|
diff = curr - last_update;
|
||||||
tm = gmtime(&diff);
|
gmtime_r(&diff, &tm);
|
||||||
|
|
||||||
snprintf(buf, len, "%d:%02d:%02d:%02d", tm->tm_yday, tm->tm_hour,
|
snprintf(buf, len, "%d:%02d:%02d:%02d", tm.tm_yday, tm.tm_hour,
|
||||||
tm->tm_min, tm->tm_sec);
|
tm.tm_min, tm.tm_sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -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)
|
static int keychain_strftime(char *buf, int bufsiz, time_t *time)
|
||||||
{
|
{
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
size_t len;
|
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;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 */
|
/* first, we update the cache if the time has changed */
|
||||||
if (cache.last != clock.tv_sec) {
|
if (cache.last != clock.tv_sec) {
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
cache.last = clock.tv_sec;
|
cache.last = clock.tv_sec;
|
||||||
tm = localtime(&cache.last);
|
localtime_r(&cache.last, &tm);
|
||||||
cache.len = strftime(cache.buf, sizeof(cache.buf),
|
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
|
/* note: it's not worth caching the subsecond part, because
|
||||||
chances are that back-to-back calls are not sufficiently close
|
chances are that back-to-back calls are not sufficiently close
|
||||||
|
|
|
@ -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)
|
static char *rip_peer_uptime(struct rip_peer *peer, char *buf, size_t len)
|
||||||
{
|
{
|
||||||
time_t uptime;
|
time_t uptime;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
|
|
||||||
/* If there is no connection has been done before print `never'. */
|
/* If there is no connection has been done before print `never'. */
|
||||||
if (peer->uptime == 0) {
|
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. */
|
/* Get current time. */
|
||||||
uptime = time(NULL);
|
uptime = time(NULL);
|
||||||
uptime -= peer->uptime;
|
uptime -= peer->uptime;
|
||||||
tm = gmtime(&uptime);
|
gmtime_r(&uptime, &tm);
|
||||||
|
|
||||||
if (uptime < ONE_DAY_SECOND)
|
if (uptime < ONE_DAY_SECOND)
|
||||||
snprintf(buf, len, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
|
snprintf(buf, len, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
|
||||||
tm->tm_sec);
|
tm.tm_sec);
|
||||||
else if (uptime < ONE_WEEK_SECOND)
|
else if (uptime < ONE_WEEK_SECOND)
|
||||||
snprintf(buf, len, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
|
snprintf(buf, len, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
|
||||||
tm->tm_min);
|
tm.tm_min);
|
||||||
else
|
else
|
||||||
snprintf(buf, len, "%02dw%dd%02dh", tm->tm_yday / 7,
|
snprintf(buf, len, "%02dw%dd%02dh", tm.tm_yday / 7,
|
||||||
tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour);
|
tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
ripd/ripd.c
10
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)
|
static void rip_vty_out_uptime(struct vty *vty, struct rip_info *rinfo)
|
||||||
{
|
{
|
||||||
time_t clock;
|
time_t clock;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
#define TIME_BUF 25
|
#define TIME_BUF 25
|
||||||
char timebuf[TIME_BUF];
|
char timebuf[TIME_BUF];
|
||||||
struct thread *thread;
|
struct thread *thread;
|
||||||
|
|
||||||
if ((thread = rinfo->t_timeout) != NULL) {
|
if ((thread = rinfo->t_timeout) != NULL) {
|
||||||
clock = thread_timer_remain_second(thread);
|
clock = thread_timer_remain_second(thread);
|
||||||
tm = gmtime(&clock);
|
gmtime_r(&clock, &tm);
|
||||||
strftime(timebuf, TIME_BUF, "%M:%S", tm);
|
strftime(timebuf, TIME_BUF, "%M:%S", &tm);
|
||||||
vty_out(vty, "%5s", timebuf);
|
vty_out(vty, "%5s", timebuf);
|
||||||
} else if ((thread = rinfo->t_garbage_collect) != NULL) {
|
} else if ((thread = rinfo->t_garbage_collect) != NULL) {
|
||||||
clock = thread_timer_remain_second(thread);
|
clock = thread_timer_remain_second(thread);
|
||||||
tm = gmtime(&clock);
|
gmtime_r(&clock, &tm);
|
||||||
strftime(timebuf, TIME_BUF, "%M:%S", tm);
|
strftime(timebuf, TIME_BUF, "%M:%S", &tm);
|
||||||
vty_out(vty, "%5s", timebuf);
|
vty_out(vty, "%5s", timebuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
static char *ripng_peer_uptime(struct ripng_peer *peer, char *buf, size_t len)
|
||||||
{
|
{
|
||||||
time_t uptime;
|
time_t uptime;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
|
|
||||||
/* If there is no connection has been done before print `never'. */
|
/* If there is no connection has been done before print `never'. */
|
||||||
if (peer->uptime == 0) {
|
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. */
|
/* Get current time. */
|
||||||
uptime = time(NULL);
|
uptime = time(NULL);
|
||||||
uptime -= peer->uptime;
|
uptime -= peer->uptime;
|
||||||
tm = gmtime(&uptime);
|
gmtime_r(&uptime, &tm);
|
||||||
|
|
||||||
if (uptime < ONE_DAY_SECOND)
|
if (uptime < ONE_DAY_SECOND)
|
||||||
snprintf(buf, len, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
|
snprintf(buf, len, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
|
||||||
tm->tm_sec);
|
tm.tm_sec);
|
||||||
else if (uptime < ONE_WEEK_SECOND)
|
else if (uptime < ONE_WEEK_SECOND)
|
||||||
snprintf(buf, len, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
|
snprintf(buf, len, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
|
||||||
tm->tm_min);
|
tm.tm_min);
|
||||||
else
|
else
|
||||||
snprintf(buf, len, "%02dw%dd%02dh", tm->tm_yday / 7,
|
snprintf(buf, len, "%02dw%dd%02dh", tm.tm_yday / 7,
|
||||||
tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour);
|
tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
static void ripng_vty_out_uptime(struct vty *vty, struct ripng_info *rinfo)
|
||||||
{
|
{
|
||||||
time_t clock;
|
time_t clock;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
#define TIME_BUF 25
|
#define TIME_BUF 25
|
||||||
char timebuf[TIME_BUF];
|
char timebuf[TIME_BUF];
|
||||||
struct thread *thread;
|
struct thread *thread;
|
||||||
|
|
||||||
if ((thread = rinfo->t_timeout) != NULL) {
|
if ((thread = rinfo->t_timeout) != NULL) {
|
||||||
clock = thread_timer_remain_second(thread);
|
clock = thread_timer_remain_second(thread);
|
||||||
tm = gmtime(&clock);
|
gmtime_r(&clock, &tm);
|
||||||
strftime(timebuf, TIME_BUF, "%M:%S", tm);
|
strftime(timebuf, TIME_BUF, "%M:%S", &tm);
|
||||||
vty_out(vty, "%5s", timebuf);
|
vty_out(vty, "%5s", timebuf);
|
||||||
} else if ((thread = rinfo->t_garbage_collect) != NULL) {
|
} else if ((thread = rinfo->t_garbage_collect) != NULL) {
|
||||||
clock = thread_timer_remain_second(thread);
|
clock = thread_timer_remain_second(thread);
|
||||||
tm = gmtime(&clock);
|
gmtime_r(&clock, &tm);
|
||||||
strftime(timebuf, TIME_BUF, "%M:%S", tm);
|
strftime(timebuf, TIME_BUF, "%M:%S", &tm);
|
||||||
vty_out(vty, "%5s", timebuf);
|
vty_out(vty, "%5s", timebuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,14 +229,15 @@ static char *vtysh_rl_gets(void)
|
||||||
static void log_it(const char *line)
|
static void log_it(const char *line)
|
||||||
{
|
{
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
struct tm *tmp = localtime(&t);
|
struct tm tmp;
|
||||||
const char *user = getenv("USER");
|
const char *user = getenv("USER");
|
||||||
char tod[64];
|
char tod[64];
|
||||||
|
|
||||||
|
localtime_r(&t, &tmp);
|
||||||
if (!user)
|
if (!user)
|
||||||
user = "boot";
|
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);
|
fprintf(logfile, "%s:%s %s\n", tod, user, line);
|
||||||
}
|
}
|
||||||
|
|
|
@ -241,24 +241,24 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn,
|
||||||
vty_out(vty, "\n");
|
vty_out(vty, "\n");
|
||||||
|
|
||||||
time_t uptime;
|
time_t uptime;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
|
|
||||||
uptime = monotime(NULL);
|
uptime = monotime(NULL);
|
||||||
uptime -= re->uptime;
|
uptime -= re->uptime;
|
||||||
tm = gmtime(&uptime);
|
gmtime_r(&uptime, &tm);
|
||||||
|
|
||||||
vty_out(vty, " Last update ");
|
vty_out(vty, " Last update ");
|
||||||
|
|
||||||
if (uptime < ONE_DAY_SECOND)
|
if (uptime < ONE_DAY_SECOND)
|
||||||
vty_out(vty, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
|
vty_out(vty, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
|
||||||
tm->tm_sec);
|
tm.tm_sec);
|
||||||
else if (uptime < ONE_WEEK_SECOND)
|
else if (uptime < ONE_WEEK_SECOND)
|
||||||
vty_out(vty, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
|
vty_out(vty, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
|
||||||
tm->tm_min);
|
tm.tm_min);
|
||||||
else
|
else
|
||||||
vty_out(vty, "%02dw%dd%02dh", tm->tm_yday / 7,
|
vty_out(vty, "%02dw%dd%02dh", tm.tm_yday / 7,
|
||||||
tm->tm_yday - ((tm->tm_yday / 7) * 7),
|
tm.tm_yday - ((tm.tm_yday / 7) * 7),
|
||||||
tm->tm_hour);
|
tm.tm_hour);
|
||||||
vty_out(vty, " ago\n");
|
vty_out(vty, " ago\n");
|
||||||
|
|
||||||
if (show_ng)
|
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_route = NULL;
|
||||||
json_object *json_labels = NULL;
|
json_object *json_labels = NULL;
|
||||||
time_t uptime;
|
time_t uptime;
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
struct vrf *vrf = NULL;
|
struct vrf *vrf = NULL;
|
||||||
rib_dest_t *dest = rib_dest_from_rnode(rn);
|
rib_dest_t *dest = rib_dest_from_rnode(rn);
|
||||||
struct nexthop_group *nhg;
|
struct nexthop_group *nhg;
|
||||||
|
|
||||||
uptime = monotime(NULL);
|
uptime = monotime(NULL);
|
||||||
uptime -= re->uptime;
|
uptime -= re->uptime;
|
||||||
tm = gmtime(&uptime);
|
gmtime_r(&uptime, &tm);
|
||||||
|
|
||||||
/* If showing fib information, use the fib view of the
|
/* If showing fib information, use the fib view of the
|
||||||
* nexthops.
|
* nexthops.
|
||||||
|
@ -475,15 +475,15 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
|
||||||
nexthop_group_active_nexthop_num(
|
nexthop_group_active_nexthop_num(
|
||||||
&(re->nhe->nhg)));
|
&(re->nhe->nhg)));
|
||||||
if (uptime < ONE_DAY_SECOND)
|
if (uptime < ONE_DAY_SECOND)
|
||||||
sprintf(buf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
|
sprintf(buf, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
|
||||||
tm->tm_sec);
|
tm.tm_sec);
|
||||||
else if (uptime < ONE_WEEK_SECOND)
|
else if (uptime < ONE_WEEK_SECOND)
|
||||||
sprintf(buf, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
|
sprintf(buf, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
|
||||||
tm->tm_min);
|
tm.tm_min);
|
||||||
else
|
else
|
||||||
sprintf(buf, "%02dw%dd%02dh", tm->tm_yday / 7,
|
sprintf(buf, "%02dw%dd%02dh", tm.tm_yday / 7,
|
||||||
tm->tm_yday - ((tm->tm_yday / 7) * 7),
|
tm.tm_yday - ((tm.tm_yday / 7) * 7),
|
||||||
tm->tm_hour);
|
tm.tm_hour);
|
||||||
|
|
||||||
json_object_string_add(json_route, "uptime", buf);
|
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)
|
if (uptime < ONE_DAY_SECOND)
|
||||||
vty_out(vty, ", %02d:%02d:%02d", tm->tm_hour,
|
vty_out(vty, ", %02d:%02d:%02d", tm.tm_hour,
|
||||||
tm->tm_min, tm->tm_sec);
|
tm.tm_min, tm.tm_sec);
|
||||||
else if (uptime < ONE_WEEK_SECOND)
|
else if (uptime < ONE_WEEK_SECOND)
|
||||||
vty_out(vty, ", %dd%02dh%02dm", tm->tm_yday,
|
vty_out(vty, ", %dd%02dh%02dm", tm.tm_yday,
|
||||||
tm->tm_hour, tm->tm_min);
|
tm.tm_hour, tm.tm_min);
|
||||||
else
|
else
|
||||||
vty_out(vty, ", %02dw%dd%02dh", tm->tm_yday / 7,
|
vty_out(vty, ", %02dw%dd%02dh", tm.tm_yday / 7,
|
||||||
tm->tm_yday - ((tm->tm_yday / 7) * 7),
|
tm.tm_yday - ((tm.tm_yday / 7) * 7),
|
||||||
tm->tm_hour);
|
tm.tm_hour);
|
||||||
vty_out(vty, "\n");
|
vty_out(vty, "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -858,7 +858,7 @@ void zserv_event(struct zserv *client, enum zserv_event event)
|
||||||
#define ZEBRA_TIME_BUF 32
|
#define ZEBRA_TIME_BUF 32
|
||||||
static char *zserv_time_buf(time_t *time1, char *buf, int buflen)
|
static char *zserv_time_buf(time_t *time1, char *buf, int buflen)
|
||||||
{
|
{
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
assert(buf != NULL);
|
assert(buf != NULL);
|
||||||
|
@ -872,17 +872,17 @@ static char *zserv_time_buf(time_t *time1, char *buf, int buflen)
|
||||||
|
|
||||||
now = monotime(NULL);
|
now = monotime(NULL);
|
||||||
now -= *time1;
|
now -= *time1;
|
||||||
tm = gmtime(&now);
|
gmtime_r(&now, &tm);
|
||||||
|
|
||||||
if (now < ONE_DAY_SECOND)
|
if (now < ONE_DAY_SECOND)
|
||||||
snprintf(buf, buflen, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
|
snprintf(buf, buflen, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
|
||||||
tm->tm_sec);
|
tm.tm_sec);
|
||||||
else if (now < ONE_WEEK_SECOND)
|
else if (now < ONE_WEEK_SECOND)
|
||||||
snprintf(buf, buflen, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
|
snprintf(buf, buflen, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
|
||||||
tm->tm_min);
|
tm.tm_min);
|
||||||
else
|
else
|
||||||
snprintf(buf, buflen, "%02dw%dd%02dh", tm->tm_yday / 7,
|
snprintf(buf, buflen, "%02dw%dd%02dh", tm.tm_yday / 7,
|
||||||
tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour);
|
tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1001,7 +1001,7 @@ static void zebra_show_stale_client_detail(struct vty *vty,
|
||||||
struct zserv *client)
|
struct zserv *client)
|
||||||
{
|
{
|
||||||
char buf[PREFIX2STR_BUFFER];
|
char buf[PREFIX2STR_BUFFER];
|
||||||
struct tm *tm;
|
struct tm tm;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
time_t uptime;
|
time_t uptime;
|
||||||
struct client_gr_info *info = NULL;
|
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);
|
s = (struct zserv *)(info->stale_client_ptr);
|
||||||
uptime = monotime(&tv);
|
uptime = monotime(&tv);
|
||||||
uptime -= s->restart_time;
|
uptime -= s->restart_time;
|
||||||
tm = gmtime(&uptime);
|
gmtime_r(&uptime, &tm);
|
||||||
|
|
||||||
vty_out(vty, "Last restart time : ");
|
vty_out(vty, "Last restart time : ");
|
||||||
if (uptime < ONE_DAY_SECOND)
|
if (uptime < ONE_DAY_SECOND)
|
||||||
vty_out(vty, "%02d:%02d:%02d",
|
vty_out(vty, "%02d:%02d:%02d",
|
||||||
tm->tm_hour, tm->tm_min,
|
tm.tm_hour, tm.tm_min,
|
||||||
tm->tm_sec);
|
tm.tm_sec);
|
||||||
else if (uptime < ONE_WEEK_SECOND)
|
else if (uptime < ONE_WEEK_SECOND)
|
||||||
vty_out(vty, "%dd%02dh%02dm",
|
vty_out(vty, "%dd%02dh%02dm",
|
||||||
tm->tm_yday, tm->tm_hour,
|
tm.tm_yday, tm.tm_hour,
|
||||||
tm->tm_min);
|
tm.tm_min);
|
||||||
else
|
else
|
||||||
vty_out(vty, "%02dw%dd%02dh",
|
vty_out(vty, "%02dw%dd%02dh",
|
||||||
tm->tm_yday / 7,
|
tm.tm_yday / 7,
|
||||||
tm->tm_yday - ((tm->tm_yday / 7)
|
tm.tm_yday - ((tm.tm_yday / 7)
|
||||||
* 7),
|
* 7),
|
||||||
tm->tm_hour);
|
tm.tm_hour);
|
||||||
vty_out(vty, " ago\n");
|
vty_out(vty, " ago\n");
|
||||||
|
|
||||||
vty_out(vty, "Stalepath removal time: %d sec\n",
|
vty_out(vty, "Stalepath removal time: %d sec\n",
|
||||||
|
|
Loading…
Reference in a new issue