#5120 closed Bugs (fixed)
boost.interprocess.detail tmp_dir_helpers.hpp get_bootstamp(std::string, bool) function problem
Reported by: | Owned by: | Ion Gaztañaga | |
---|---|---|---|
Milestone: | To Be Determined | Component: | interprocess |
Version: | Boost 1.45.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Because of bug #4230, I switched to boost 1.45.0 from 1.42.0, but, application unexpectedly crashes on Windows platform. After short investigation in source code, I noticed that problem lies in get_bootstamp(std::string&, bool) function, which has changed in latest release, more precisely, folder name construction has changed. In some cases, function winapi::get_last_bootup_time(std::string&) which calls get_wmi_class_attribute, returns empty string instead of last bootup time. In that case, code inside if statement: if( 0 == CoInitializeSecurity( 0, -1, 0, 0, RPC_C_AUTHN_LEVEL_PKT_IG, RPC_C_IMP_LEVEL_IMPERSONATE_IG, 0, EOAC_NONE_IG, 0 ) )
{
IWbemLocator_IG * pIWbemLocator = 0;
.... } has not been reached, actually, CoInitializeSecurity returns: RPC_E_TOO_LATE CoInitializeSecurity has already been called. In this case, shared memory is created in: C:\ProgramData\boost_interprocess\foo.shm instead of C:\ProgramData\boost_interprocess\last_boot_time\foo.shm.
This causes that next time when application tries to open created shared memory, it has been deleted, and interprocess exception file not found has been thrown. I don't know is this behavior a real bug, or I'm doing something wrong, but application has worked perfectly with 1.42.0 version, but due to bug #4320 I had to switch on 1.45.0. Also, I'm interesting about reasons for shared memory folder name construction has been changed, because, I tried 1.45.0 with an old way (I edit get_bootstamp), and it worked!
Change History (5)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
I noticed the same bug. CoInitializeSecurity returns RPC_E_TOO_LATE the second time it is called. Isn't it an error for CoInitializeSecurity to be called more than once for a process? I'll try and revert the get_last_bootup_time to the old version.
Here is the message I sent to boost-users@… in case you need more info:
I think I have found a bug in the boost interprocess library. I would be thankful for any workaround.
I am maintaining some code that was upgraded to use boost_1_45_0 running on windows7.
We have some dll that creates a file for sharing:
C:\ProgramData/boost_interprocess/20110321233336.335895/share_memory_segment_somenameengine_0
The dll launches a exe and shares some memory with it. However this exe tries to read the shared memory at location:
C:\ProgramData/boost_interprocessshare_memory_segment_somenameengine_0
The folder name "20110321233336.335895" is missing in that path name.
Debugging this is seems to be because the boost library tries to get the windows system boot time by calling boost::interprocess::winapi::get_last_bootup_time.. which fails for some reason. The weird thing is that the exe (indirectly) calls this twice, and the first time it works but not the second time. (The dll also calls it twice but that works just fine.)
In get_wmi_class_attribute the time this if statement evaulates to true, next time it does not:
if( 0 == CoInitializeSecurity( 0, -1, 0, 0, RPC_C_AUTHN_LEVEL_PKT_IG, RPC_C_IMP_LEVEL_IMPERSONATE_IG, 0, EOAC_NONE_IG, 0 ) )
Here is the call stack for context:
First time work fine CoInitializeSecurity works..
boost::interprocess::winapi::get_wmi_class_attribute(std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > & strValue="", const wchar_t * wmi_class=0x01595704, const wchar_t * wmi_class_var=0x01595730) Line 1457 C++
boost::interprocess::winapi::get_last_bootup_time(std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > & strValue="") Line 1554 C++ boost::interprocess::winapi::get_last_bootup_time(std::basic_string<char,std::char_traits<char>,std::allocator<char> > & str="") Line 1569 C++ boost::interprocess::detail::get_bootstamp(std::basic_string<char,std::char_traits<char>,std::allocator<char> > & s="C:\ProgramData/boost_interprocess/", bool add=true) Line 41 C++ boost::interprocess::detail::tmp_folder(std::basic_string<char,std::char_traits<char>,std::allocator<char> > & tmp_name="C:\ProgramData/boost_interprocess/") Line 108 C++ !!!boost::interprocess::detail::create_tmp_and_clean_old(std::basic_string<char,std::char_traits<char>,std::allocator<char> > & tmp_name="C:\ProgramData/boost_interprocess/") Line 134 C++ !!!boost::interprocess::detail::create_tmp_and_clean_old_and_get_filename(const char * filename=0x002502f8, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & tmp_name="C:\ProgramData/boost_interprocess/") Line 154 C++ boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t type=DoOpen, const char * filename=0x002502f8, boost::interprocess::mode_t mode=-2147483648, const boost::interprocess::permissions & perm={...}) Line 181 C++ boost::interprocess::shared_memory_object::shared_memory_object(boost::interprocess::open_only_t formal={...}, const char * name=0x002502f8, boost::interprocess::mode_t mode=-2147483648) Line 76 C++
Second time CoInitializeSecurity does not work
boost::interprocess::winapi::get_wmi_class_attribute(std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > & strValue="", const wchar_t * wmi_class=0x01595704, const wchar_t * wmi_class_var=0x01595730) Line 1457 C++
boost::interprocess::winapi::get_last_bootup_time(std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > & strValue="") Line 1554 C++ boost::interprocess::winapi::get_last_bootup_time(std::basic_string<char,std::char_traits<char>,std::allocator<char> > & str="") Line 1569 C++ boost::interprocess::detail::get_bootstamp(std::basic_string<char,std::char_traits<char>,std::allocator<char> > & s="C:\ProgramData/boost_interprocess/", bool add=true) Line 41 C++ boost::interprocess::detail::tmp_folder(std::basic_string<char,std::char_traits<char>,std::allocator<char> > & tmp_name="C:\ProgramData/boost_interprocess/") Line 108 C++ !!!boost::interprocess::detail::tmp_filename(const char * filename=0x002502f8, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & tmp_name="C:\ProgramData/boost_interprocess/") Line 114 C++ !!!boost::interprocess::detail::create_tmp_and_clean_old_and_get_filename(const char * filename=0x002502f8, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & tmp_name="C:\ProgramData/boost_interprocess/") Line 155 C++ boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t type=DoOpen, const char * filename=0x002502f8, boost::interprocess::mode_t mode=-2147483648, const boost::interprocess::permissions & perm={...}) Line 181 C++ boost::interprocess::shared_memory_object::shared_memory_object(boost::interprocess::open_only_t formal={...}, const char * name=0x002502f8, boost::interprocess::mode_t mode=-2147483648) Line 76 C++
Thanks, Patrik
comment:3 by , 12 years ago
Please try Boost 1.46 or trunk code to see if this has been already fixed
comment:4 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
WMI is provoking a lot of problems for Boost Interprocess users. I've decided to remove bootstamp use in windows to obtain kernel persistence in Windows. This means that windows shared memory/queues will survive to reboots, but this behaviour is allowed by POSIX. Using bootstamps to detect reboots is doing more harm than good.
WMI is removed in Boost 1.47
comment:5 by , 11 years ago
Since WMI usage was not removed for 1.47.0 please have a look at my additions to #5392!
I messed up bug numbers! In both cases I was thinking on bug #4350: Shared memory permission limitations
Sorry, for mistake. Best regards Darko