summaryrefslogtreecommitdiffstats
path: root/zebra/zserv.c
diff options
context:
space:
mode:
authorMark Stapp <mjs@voltanet.io>2020-03-05 20:06:46 +0100
committerMark Stapp <mjs@voltanet.io>2020-03-09 16:12:32 +0100
commitd0636ead31ccfc9f6c27d02617d5965e3111d4ad (patch)
treef1c383042125411fc44acd65febdf43ce1f1de17 /zebra/zserv.c
parentMerge pull request #5919 from qlyoung/fix-vrrp-mvl-uaf (diff)
downloadfrr-d0636ead31ccfc9f6c27d02617d5965e3111d4ad.tar.xz
frr-d0636ead31ccfc9f6c27d02617d5965e3111d4ad.zip
lib, *: add a common time interval formatting api
Add a common api that formats a time interval into a string with different output for short and longer intervals. We do this in several places, for cli/ui output. Signed-off-by: Mark Stapp <mjs@voltanet.io>
Diffstat (limited to 'zebra/zserv.c')
-rw-r--r--zebra/zserv.c42
1 files changed, 9 insertions, 33 deletions
diff --git a/zebra/zserv.c b/zebra/zserv.c
index 40aa9010c..7f806d82c 100644
--- a/zebra/zserv.c
+++ b/zebra/zserv.c
@@ -858,7 +858,6 @@ 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;
time_t now;
assert(buf != NULL);
@@ -872,17 +871,9 @@ static char *zserv_time_buf(time_t *time1, char *buf, int buflen)
now = monotime(NULL);
now -= *time1;
- gmtime_r(&now, &tm);
-
- if (now < ONE_DAY_SECOND)
- 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);
- else
- snprintf(buf, buflen, "%02dw%dd%02dh", tm.tm_yday / 7,
- tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour);
+
+ frrtime_to_interval(now, buf, buflen);
+
return buf;
}
@@ -1001,8 +992,6 @@ static void zebra_show_stale_client_detail(struct vty *vty,
struct zserv *client)
{
char buf[PREFIX2STR_BUFFER];
- struct tm tm;
- struct timeval tv;
time_t uptime;
struct client_gr_info *info = NULL;
struct zserv *s = NULL;
@@ -1028,26 +1017,13 @@ static void zebra_show_stale_client_detail(struct vty *vty,
if (ZEBRA_CLIENT_GR_ENABLED(info->capabilities)) {
if (info->stale_client_ptr) {
s = (struct zserv *)(info->stale_client_ptr);
- uptime = monotime(&tv);
+ uptime = monotime(NULL);
uptime -= s->restart_time;
- 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);
- else if (uptime < ONE_WEEK_SECOND)
- 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, " ago\n");
+
+ frrtime_to_interval(uptime, buf, sizeof(buf));
+
+ vty_out(vty, "Last restart time : %s ago\n",
+ buf);
vty_out(vty, "Stalepath removal time: %d sec\n",
info->stale_removal_time);