From 9689fe61994428c8588a9d00d618390c983dc91b Mon Sep 17 00:00:00 2001 From: Carol Hebert Date: Wed, 9 Jul 2008 05:55:55 +0000 Subject: [PATCH] Bernard Manjou fix for sel and sdr timestamp reporting issues --- ipmitool/lib/ipmi_pef.c | 2 +- ipmitool/lib/ipmi_sdr.c | 2 +- ipmitool/lib/ipmi_sel.c | 30 ++++++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/ipmitool/lib/ipmi_pef.c b/ipmitool/lib/ipmi_pef.c index 3d3ff2f..fa96688 100644 --- a/ipmitool/lib/ipmi_pef.c +++ b/ipmitool/lib/ipmi_pef.c @@ -748,7 +748,7 @@ ipmi_pef_get_status(struct ipmi_intf * intf) #endif ts = (time_t)timei; - strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", localtime(&ts)); + strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", gmtime(&ts)); ipmi_pef_print_str("Last SEL addition", tbuf); ipmi_pef_print_2xd("Last SEL record ID", rsp->data[5], rsp->data[4]); diff --git a/ipmitool/lib/ipmi_sdr.c b/ipmitool/lib/ipmi_sdr.c index e65e0f9..9ea20aa 100644 --- a/ipmitool/lib/ipmi_sdr.c +++ b/ipmitool/lib/ipmi_sdr.c @@ -3819,7 +3819,7 @@ ipmi_sdr_timestamp(uint32_t stamp) memset(tbuf, 0, 40); if (stamp) strftime(tbuf, sizeof (tbuf), "%m/%d/%Y %H:%M:%S", - localtime(&s)); + gmtime(&s)); return tbuf; } diff --git a/ipmitool/lib/ipmi_sel.c b/ipmitool/lib/ipmi_sel.c index 037612e..fa081d5 100644 --- a/ipmitool/lib/ipmi_sel.c +++ b/ipmitool/lib/ipmi_sel.c @@ -223,7 +223,7 @@ ipmi_sel_timestamp(uint32_t stamp) static char tbuf[40]; time_t s = (time_t)stamp; memset(tbuf, 0, 40); - strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", localtime(&s)); + strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", gmtime(&s)); return tbuf; } @@ -232,7 +232,7 @@ ipmi_sel_timestamp_date(uint32_t stamp) { static char tbuf[11]; time_t s = (time_t)stamp; - strftime(tbuf, sizeof(tbuf), "%m/%d/%Y", localtime(&s)); + strftime(tbuf, sizeof(tbuf), "%m/%d/%Y", gmtime(&s)); return tbuf; } @@ -241,7 +241,7 @@ ipmi_sel_timestamp_time(uint32_t stamp) { static char tbuf[9]; time_t s = (time_t)stamp; - strftime(tbuf, sizeof(tbuf), "%H:%M:%S", localtime(&s)); + strftime(tbuf, sizeof(tbuf), "%H:%M:%S", gmtime(&s)); return tbuf; } @@ -1821,7 +1821,7 @@ ipmi_sel_get_time(struct ipmi_intf * intf) time = (time_t)timei; #endif - strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", localtime(&time)); + strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", gmtime(&time)); printf("%s\n", tbuf); return 0; @@ -1866,6 +1866,28 @@ ipmi_sel_set_time(struct ipmi_intf * intf, const char * time_string) } } + { + //modify UTC time to local time expressed in number of seconds from 1/1/70 0:0:0 1970 GMT + struct tm * tm_tmp; + int gt_year,gt_yday,gt_hour,lt_year,lt_yday,lt_hour; + int delta_hour; + tm_tmp=gmtime(&t); + gt_year=tm_tmp->tm_year; + gt_yday=tm_tmp->tm_yday; + gt_hour=tm_tmp->tm_hour; + tm_tmp=localtime(&t); + lt_year=tm_tmp->tm_year; + lt_yday=tm_tmp->tm_yday; + lt_hour=tm_tmp->tm_hour; + delta_hour=lt_hour - gt_hour; + if ( (lt_year > gt_year) || ((lt_year == gt_year) && (lt_yday > gt_yday)) ) + delta_hour += 24; + if ( (lt_year < gt_year) || ((lt_year == gt_year) && (lt_yday < gt_yday)) ) + delta_hour -= 24; + + t += (delta_hour * 60 * 60); + } + timei = (uint32_t)t; req.msg.data = (uint8_t *)&timei; req.msg.data_len = 4;