diff options
| author | Renato Westphal <renato@opensourcerouting.org> | 2019-08-10 17:57:43 -0300 | 
|---|---|---|
| committer | Olivier Dugeon <olivier.dugeon@orange.com> | 2020-04-30 11:28:51 +0200 | 
| commit | 9cd06cd7b9ee0a966d7ae9a7d23385a2d287845d (patch) | |
| tree | 800e9b5cff1044cbd7c8365bc1ceb8feda88dd7b /isisd/isis_misc.c | |
| parent | 3056368301733d2e8f956a87a19602783ee33602 (diff) | |
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>
Diffstat (limited to 'isisd/isis_misc.c')
| -rw-r--r-- | isisd/isis_misc.c | 20 | 
1 files changed, 20 insertions, 0 deletions
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];  | 
