Refactor timestamp handling

Handle all date/time stamps uniformly, taking in account the host
endianness. Respect the local time zone and the '-Z' option for
all ipmitool commands. Unify the date and time formatting.
Add correct handling of IPMI timestamps 'since system startup'
and for 'unspecified' timestamps.

Partially resolves ipmitool/ipmitool#23

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
This commit is contained in:
Alexander Amelkin
2018-07-26 19:40:44 +03:00
parent a4ac8ce4ab
commit f0d5c17ea7
16 changed files with 485 additions and 367 deletions

View File

@@ -52,6 +52,7 @@
#include <ipmitool/ipmi_entity.h>
#include <ipmitool/ipmi_constants.h>
#include <ipmitool/ipmi_strings.h>
#include <ipmitool/ipmi_time.h>
#if HAVE_CONFIG_H
# include <config.h>
@@ -4209,24 +4210,6 @@ ipmi_sdr_get_info(struct ipmi_intf *intf,
return 0;
}
/* ipmi_sdr_timestamp - return string from timestamp value
*
* @stamp: 32bit timestamp
*
* returns pointer to static buffer
*/
static char *
ipmi_sdr_timestamp(time_t stamp)
{
static char tbuf[40];
time_t s = (time_t) stamp;
memset(tbuf, 0, 40);
if (stamp)
strftime(tbuf, sizeof (tbuf), "%m/%d/%Y %H:%M:%S",
gmtime(&s));
return tbuf;
}
/*
* ipmi_sdr_print_info
*
@@ -4278,7 +4261,7 @@ ipmi_sdr_print_info(struct ipmi_intf *intf)
{
timestamp = ipmi32toh(sdr_repository_info
.most_recent_addition_timestamp);
printf("%s\n", ipmi_sdr_timestamp(timestamp));
printf("%s\n", ipmi_timestamp_numeric(timestamp));
}
else {
printf("NA\n");
@@ -4288,7 +4271,7 @@ ipmi_sdr_print_info(struct ipmi_intf *intf)
if(sdr_repository_info.delete_sdr_supported) {
timestamp = ipmi32toh(sdr_repository_info
.most_recent_erase_timestamp);
printf("%s\n", ipmi_sdr_timestamp(timestamp));
printf("%s\n", ipmi_timestamp_numeric(timestamp));
}
else {
printf("NA\n");