From a4c8a164d4f618d9c3147857b2809f1d080879a3 Mon Sep 17 00:00:00 2001 From: Tom Kent Date: Thu, 16 Apr 2015 08:51:27 -0500 Subject: [PATCH 1/2] Adding fallback to WMI bootstamp If the event log has been cleared, it will no longer contain the startup timestamp. In this case, we could fallback to using the WMI derived timestamp instead of the event log timestamp. --- include/boost/interprocess/detail/win32_api.hpp | 26 +++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/include/boost/interprocess/detail/win32_api.hpp b/include/boost/interprocess/detail/win32_api.hpp index b924341c..21c52266 100644 --- a/include/boost/interprocess/detail/win32_api.hpp +++ b/include/boost/interprocess/detail/win32_api.hpp @@ -2147,11 +2147,7 @@ inline bool get_wmi_class_attribute( std::wstring& strValue, const wchar_t *wmi_ return bRet; } -#ifdef BOOST_INTERPROCESS_BOOTSTAMP_IS_LASTBOOTUPTIME - -//Obtains the bootup time from WMI LastBootUpTime. -//This time seems to change with hibernation and clock synchronization so avoid it. -inline bool get_last_bootup_time( std::wstring& strValue ) +inline bool get_wmi_last_bootup_time( std::wstring& strValue) { bool ret = get_wmi_class_attribute(strValue, L"Win32_OperatingSystem", L"LastBootUpTime"); std::size_t timezone = strValue.find(L'+'); @@ -2162,10 +2158,10 @@ inline bool get_last_bootup_time( std::wstring& strValue ) if(timezone != std::wstring::npos){ strValue.erase(timezone); } - return ret; + return ret; } -inline bool get_last_bootup_time( std::string& str ) +inline bool get_wmi_last_bootup_time( std::string& str ) { std::wstring wstr; bool ret = get_last_bootup_time(wstr); @@ -2176,6 +2172,20 @@ inline bool get_last_bootup_time( std::string& str ) return ret; } +#ifdef BOOST_INTERPROCESS_BOOTSTAMP_IS_LASTBOOTUPTIME + +//Obtains the bootup time from WMI LastBootUpTime. +//This time seems to change with hibernation and clock synchronization so avoid it. +inline bool get_last_bootup_time( std::wstring& strValue ) +{ + return get_wmi_last_bootup_time(strValue); +} + +inline bool get_last_bootup_time( std::string& str ) +{ + return get_wmi_last_bootup_time(str); +} + #else // Loop through the buffer and obtain the contents of the @@ -2252,7 +2262,7 @@ inline bool get_last_bootup_time(std::string &stamp) } } else{ //Not found or EOF - return false; + return get_wmi_last_bootup_time(stamp); } } else From 8941a07d2f356e934de793a6a6e7b8315e7d0c29 Mon Sep 17 00:00:00 2001 From: Tom Kent Date: Thu, 16 Apr 2015 09:28:05 -0500 Subject: [PATCH 2/2] Missed passthrough call. Missed adding the new wmi part to the wstring passthrough call. --- include/boost/interprocess/detail/win32_api.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/interprocess/detail/win32_api.hpp b/include/boost/interprocess/detail/win32_api.hpp index 21c52266..65ca9f4b 100644 --- a/include/boost/interprocess/detail/win32_api.hpp +++ b/include/boost/interprocess/detail/win32_api.hpp @@ -2164,7 +2164,7 @@ inline bool get_wmi_last_bootup_time( std::wstring& strValue) inline bool get_wmi_last_bootup_time( std::string& str ) { std::wstring wstr; - bool ret = get_last_bootup_time(wstr); + bool ret = get_wmi_last_bootup_time(wstr); str.resize(wstr.size()); for(std::size_t i = 0, max = str.size(); i != max; ++i){ str[i] = '0' + (wstr[i]-L'0');