mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-07 06:03:10 +00:00
isisd: split vty_out_timestr() into two helper functions
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>
This commit is contained in:
parent
3056368301
commit
9cd06cd7b9
@ -538,6 +538,26 @@ void log_multiline(int priority, const char *prefix, const char *format, ...)
|
|||||||
XFREE(MTYPE_TMP, p);
|
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, ...)
|
void vty_multiline(struct vty *vty, const char *prefix, const char *format, ...)
|
||||||
{
|
{
|
||||||
char shortbuf[256];
|
char shortbuf[256];
|
||||||
|
@ -80,6 +80,7 @@ enum { ISIS_UI_LEVEL_BRIEF,
|
|||||||
#include "lib/log.h"
|
#include "lib/log.h"
|
||||||
void log_multiline(int priority, const char *prefix, const char *format, ...)
|
void log_multiline(int priority, const char *prefix, const char *format, ...)
|
||||||
PRINTFRR(3, 4);
|
PRINTFRR(3, 4);
|
||||||
|
char *log_uptime(time_t uptime, char *buf, size_t nbuf);
|
||||||
struct vty;
|
struct vty;
|
||||||
void vty_multiline(struct vty *vty, const char *prefix, const char *format, ...)
|
void vty_multiline(struct vty *vty, const char *prefix, const char *format, ...)
|
||||||
PRINTFRR(3, 4);
|
PRINTFRR(3, 4);
|
||||||
|
Loading…
Reference in New Issue
Block a user