From: Dave H. <hel...@us...> - 2014-10-21 14:52:58
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "cmpi-base - Base OS CMPI Providers". The branch, master has been updated via 20e84c24e0a730fcf38d378417f6bae4af98abba (commit) from 3f41cf1d3ea50eb0563c6422f7919c19330c96f0 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 20e84c24e0a730fcf38d378417f6bae4af98abba Author: Dave Heller <hel...@us...> Date: Tue Oct 21 10:52:23 2014 -0400 Fixed SBLIM-2737: datetime values do not adjust for DST ----------------------------------------------------------------------- Summary of changes: ChangeLog | 7 ++++++ NEWS | 1 + OSBase_Common.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ OSBase_Common.h | 1 + OSBase_OperatingSystem.c | 23 ++++++--------------- OSBase_UnixProcess.c | 6 +---- 6 files changed, 64 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index dd1fe2c..8baa177 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2014-10-24 Dave Heller <hel...@us...> + + * NEWS, OSBase_Common.c, OSBase_Common.h, OSBase_OperatingSystem.c, + OSBase_UnixProcess.c + + Fixed SBLIM-2737: datetime values do not adjust for DST + 2013-11-16 Dave Heller <hel...@us...> * NEWS, contributions.txt, OSBase_Common.c: diff --git a/NEWS b/NEWS index 6c77e35..10c7f26 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ Bugs Fixed: - SBLIM-2634: incorrect max cpu frequency - SBLIM-2644: wrong UserModeTime and KernelModeTime - SBLIM-2698: system name might have empty domainname +- SBLIM-2737: datetime values do not adjust for DST Changes in Version 1.6.2 ======================== diff --git a/OSBase_Common.c b/OSBase_Common.c index 46c76e8..65d285b 100644 --- a/OSBase_Common.c +++ b/OSBase_Common.c @@ -247,6 +247,53 @@ signed short get_os_timezone() { return CIM_OS_TIMEZONE; } +/** ---------------------------------------------------------------------------- + * Convert time_t time (seconds since epoch) to a CMPIDateTime-like string in + * the requested format: + * @param local 1 = result in localtime; 0 = result in GMT + * @param adj_dst 1 = result adjusted for DST (only meaningful for local) + * @return a string containing the requested datetime + * -------------------------------------------------------------------------- */ + +char *sse_to_cmpi_datetime_str(long sse, int local, int adj_dst) { + char *dt = malloc(26); + struct tm bdtime; + struct tm *(*func)(); + int offset = 0; + + _OSBASE_TRACE(4, + ("--- sse_to_cmpi_datetime_str() called for sse=%lu local=%d adj_dst=%d\n", + sse, local, adj_dst)); + + if (local && adj_dst) { + func = &localtime_r; + } + else { + func = &gmtime_r; + adj_dst = 0; + if (local) + sse -= timezone; + } + + if (func(&sse, &bdtime)) { + if (adj_dst) + offset = bdtime.tm_gmtoff / 60; /* adjusted for DST */ + else if (local) + offset = - timezone / 60; /* not adjusted for DST */ + + strftime(dt, 26, "%Y%m%d%H%M%S.000000", &bdtime); + sprintf(dt, "%s%+04d", dt, offset); + } + + _OSBASE_TRACE(4, + ("--- sse_to_cmpi_datetime_str() : exiting, returned value: %s", dt)); + return dt; +} + +/* ---------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ + unsigned long _get_os_boottime() { char ** hdout = NULL; int rc = 0; diff --git a/OSBase_Common.h b/OSBase_Common.h index a290104..ae54e07 100644 --- a/OSBase_Common.h +++ b/OSBase_Common.h @@ -57,6 +57,7 @@ static inline char * get_os_name() { return CIM_OS_NAME; } signed short get_os_timezone(); unsigned long _get_os_boottime(); void _cat_timezone( char * str, signed short zone ); +char * sse_to_cmpi_datetime_str(long sse, int local, int adj_dst); /* ---------------------------------------------------------------------------*/ diff --git a/OSBase_OperatingSystem.c b/OSBase_OperatingSystem.c index 2259e3f..3467014 100644 --- a/OSBase_OperatingSystem.c +++ b/OSBase_OperatingSystem.c @@ -104,12 +104,12 @@ int get_operatingsystem_data( struct cim_operatingsystem ** sptr ){ // fprintf( stderr,"%lli : %lli: %lli: %lli\n",(*sptr)->totalPhysMem,(*sptr)->freePhysMem,(*sptr)->totalSwapMem,(*sptr)->freeSwapMem); - /* CurrentTimeZone */ - (*sptr)->curTimeZone = get_os_timezone(); - /* LocalDateTime */ (*sptr)->localDate = get_os_localdatetime(); + /* CurrentTimeZone */ + (*sptr)->curTimeZone = atoi((*sptr)->localDate + 21); + /* InstallDate */ (*sptr)->installDate = get_os_installdate(); @@ -289,14 +289,10 @@ char * get_os_lastbootup() { up = _get_os_boottime(); if( up == 0 ) { - _OSBASE_TRACE(4,("--- get_os_lastbootup() failed : was not able to set last boot time")); + _OSBASE_TRACE(1,("--- get_os_lastbootup() failed : was not able to set last boot time")); return NULL; } - if( gmtime_r( &up, &uptm ) != NULL ) { - uptime = (char*)malloc(26); - strftime(uptime,26,"%Y%m%d%H%M%S.000000",&uptm); - _cat_timezone(uptime, get_os_timezone()); - } + uptime = sse_to_cmpi_datetime_str(up, 1, 1); _OSBASE_TRACE(4,("--- get_os_lastbootup() exited : %s",uptime)); return uptime; @@ -310,13 +306,8 @@ char * get_os_localdatetime() { _OSBASE_TRACE(4,("--- get_os_localdatetime() called")); - sec=time(NULL) + get_os_timezone()*60; - if( gmtime_r( &sec , &cttm) != NULL ) { - tm = (char*)malloc(26); - strftime(tm,26,"%Y%m%d%H%M%S.000000",&cttm); - _cat_timezone(tm, get_os_timezone()); - } - + tm = sse_to_cmpi_datetime_str(time(NULL), 1, 1); + _OSBASE_TRACE(4,("--- get_os_localdatetime() exited : %s",tm)); return tm; } diff --git a/OSBase_UnixProcess.c b/OSBase_UnixProcess.c index b7c050e..0dc6d38 100644 --- a/OSBase_UnixProcess.c +++ b/OSBase_UnixProcess.c @@ -241,11 +241,7 @@ static int _process_data( char * phd , struct cim_process ** sptr ){ if( uptime == 0 ) { (*sptr)->createdate = NULL; } else { ctime = (ctime/100)+uptime; - if( gmtime_r( &ctime , &tmdate) != NULL ) { - (*sptr)->createdate = (char*)malloc(26); - rc = strftime((*sptr)->createdate,26,"%Y%m%d%H%M%S.000000",&tmdate); - _cat_timezone((*sptr)->createdate, get_os_timezone()); - } + (*sptr)->createdate = sse_to_cmpi_datetime_str(ctime, 1, 1); } // fprintf(stderr,"(*sptr)->createdate: %s\n",(*sptr)->createdate); /* fprintf(stderr,"PID: %s ... um:%lli; km:%lli;\num:%lli; km:%lli; cd_sec:%li\n", hooks/post-receive -- cmpi-base - Base OS CMPI Providers |