diff --git a/isisd/isis_misc.c b/isisd/isis_misc.c index 25f7f8609b..27d06e8da7 100644 --- a/isisd/isis_misc.c +++ b/isisd/isis_misc.c @@ -538,6 +538,26 @@ void log_multiline(int priority, const char *prefix, const char *format, ...) XFREE(MTYPE_TMP, p); } +char *log_uptime(time_t uptime, char *buf, size_t nbuf) +{ + struct tm *tm; + time_t difftime = time(NULL); + difftime -= uptime; + tm = gmtime(&difftime); + + if (difftime < ONE_DAY_SECOND) + snprintf(buf, nbuf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, + tm->tm_sec); + else if (difftime < ONE_WEEK_SECOND) + snprintf(buf, nbuf, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour, + tm->tm_min); + else + snprintf(buf, nbuf, "%02dw%dd%02dh", tm->tm_yday / 7, + tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour); + + return buf; +} + void vty_multiline(struct vty *vty, const char *prefix, const char *format, ...) { char shortbuf[256]; diff --git a/isisd/isis_misc.h b/isisd/isis_misc.h index fbfabaf24f..5cdbbfb058 100644 --- a/isisd/isis_misc.h +++ b/isisd/isis_misc.h @@ -80,6 +80,7 @@ enum { ISIS_UI_LEVEL_BRIEF, #include "lib/log.h" void log_multiline(int priority, const char *prefix, const char *format, ...) PRINTFRR(3, 4); +char *log_uptime(time_t uptime, char *buf, size_t nbuf); struct vty; void vty_multiline(struct vty *vty, const char *prefix, const char *format, ...) PRINTFRR(3, 4);