]> git.puffer.fish Git - matthieu/frr.git/commitdiff
isisd: split vty_out_timestr() into two helper functions
authorRenato Westphal <renato@opensourcerouting.org>
Sat, 10 Aug 2019 20:57:43 +0000 (17:57 -0300)
committerOlivier Dugeon <olivier.dugeon@orange.com>
Thu, 30 Apr 2020 09:28:51 +0000 (11:28 +0200)
The new log_uptime() function logs an UNIX timestamp to a buffer
provided by the user. It's very flexibile and can be used in a
variety of contexts, different from vty_out_timestr() which is too
tied to the VTY code.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
isisd/isis_misc.c
isisd/isis_misc.h

index 25f7f8609bcd9be6ef898eefea6e69856e652d2a..27d06e8da7344149fb770b5f986ac8fb3c32f5ad 100644 (file)
@@ -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];
index fbfabaf24f40726c6bbaf252e8ca2089170cb584..5cdbbfb0581513af01c1d340526440cd56f3ee4e 100644 (file)
@@ -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);