Boost C++ Libraries: Ticket #5120: boost.interprocess.detail tmp_dir_helpers.hpp get_bootstamp(std::string, bool) function problem https://svn.boost.org/trac10/ticket/5120 <p> Because of bug <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4230" title="#4230: Patches: [Patch] Fix missing/broken friend function definitions in class templates (closed: fixed)">#4230</a>, 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&amp;, 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&amp;) which calls get_wmi_class_attribute, returns empty string instead of last bootup time. In that case, code inside if statement: if( 0 == <a class="missing wiki">CoInitializeSecurity</a>( 0, -1, 0, 0, RPC_C_AUTHN_LEVEL_PKT_IG, RPC_C_IMP_LEVEL_IMPERSONATE_IG, 0, EOAC_NONE_IG, 0 ) ) </p> <blockquote> <p> { </p> <blockquote> <p> IWbemLocator_IG * pIWbemLocator = 0; </p> </blockquote> </blockquote> <p> .... } has not been reached, actually, <a class="missing wiki">CoInitializeSecurity</a> returns: RPC_E_TOO_LATE <a class="missing wiki">CoInitializeSecurity</a> has already been called. In this case, shared memory is created in: C:\<a class="missing wiki">ProgramData</a>\boost_interprocess\foo.shm instead of C:\<a class="missing wiki">ProgramData</a>\boost_interprocess\last_boot_time\foo.shm. </p> <p> 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 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4320" title="#4320: Bugs: warning: missing braces around initializer for ... (closed: duplicate)">#4320</a> 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! </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5120 Trac 1.4.3 Darko Nesovic <nesovicdarko@…> Tue, 25 Jan 2011 14:42:40 GMT <link>https://svn.boost.org/trac10/ticket/5120#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5120#comment:1</guid> <description> <p> I messed up bug numbers! In both cases I was thinking on bug <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4350" title="#4350: Bugs: Shared memory permission limitations (closed: fixed)">#4350</a>: Shared memory permission limitations </p> <p> Sorry, for mistake. Best regards Darko </p> </description> <category>Ticket</category> </item> <item> <author>petke@…</author> <pubDate>Thu, 24 Mar 2011 18:45:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5120#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5120#comment:2</guid> <description> <p> I noticed the same bug. <a class="missing wiki">CoInitializeSecurity</a> returns RPC_E_TOO_LATE the second time it is called. Isn't it an error for <a class="missing wiki">CoInitializeSecurity</a> to be called more than once for a process? I'll try and revert the get_last_bootup_time to the old version. </p> <p> Here is the message I sent to boost-users@… in case you need more info: </p> <p> I think I have found a bug in the boost interprocess library. I would be thankful for any workaround. </p> <p> I am maintaining some code that was upgraded to use boost_1_45_0 running on windows7. </p> <p> We have some dll that creates a file for sharing: </p> <p> C:\<a class="missing wiki">ProgramData</a>/boost_interprocess/20110321233336.335895/share_memory_segment_somenameengine_0 </p> <p> The dll launches a exe and shares some memory with it. However this exe tries to read the shared memory at location: </p> <p> C:\<a class="missing wiki">ProgramData</a>/boost_interprocess<em>share_memory_segment_somenameengine_0 </em></p> <p> The folder name "20110321233336.335895" is missing in that path name. </p> <p> 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.) </p> <p> In get_wmi_class_attribute the time this if statement evaulates to true, next time it does not: </p> <blockquote> <p> if( 0 == <a class="missing wiki">CoInitializeSecurity</a>( 0, -1, 0, 0, RPC_C_AUTHN_LEVEL_PKT_IG, RPC_C_IMP_LEVEL_IMPERSONATE_IG, 0, EOAC_NONE_IG, 0 ) ) </p> </blockquote> <p> Here is the call stack for context: </p> <p> First time work fine <a class="missing wiki">CoInitializeSecurity</a> works.. </p> <blockquote class="citation"> <blockquote> <p> boost::interprocess::winapi::get_wmi_class_attribute(std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt; &amp; strValue="", const wchar_t * wmi_class=0x01595704, const wchar_t * wmi_class_var=0x01595730) Line 1457 C++ </p> </blockquote> </blockquote> <blockquote> <p> boost::interprocess::winapi::get_last_bootup_time(std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt; &amp; strValue="") Line 1554 C++ boost::interprocess::winapi::get_last_bootup_time(std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; str="") Line 1569 C++ boost::interprocess::detail::get_bootstamp(std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; s="C:\<a class="missing wiki">ProgramData</a>/boost_interprocess/", bool add=true) Line 41 C++ boost::interprocess::detail::tmp_folder(std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; tmp_name="C:\<a class="missing wiki">ProgramData</a>/boost_interprocess/") Line 108 C++ !!!boost::interprocess::detail::create_tmp_and_clean_old(std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; tmp_name="C:\<a class="missing wiki">ProgramData</a>/boost_interprocess/") Line 134 C++ !!!boost::interprocess::detail::create_tmp_and_clean_old_and_get_filename(const char * filename=0x002502f8, std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; tmp_name="C:\<a class="missing wiki">ProgramData</a>/boost_interprocess/") Line 154 C++ boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t type=<a class="missing wiki">DoOpen</a>, const char * filename=0x002502f8, boost::interprocess::mode_t mode=-2147483648, const boost::interprocess::permissions &amp; perm={...}) Line 181 C++ boost::interprocess::shared_memory_object::shared_memory_object(boost::interprocess::open_only_t <span class="underline">formal={...}, const char * name=0x002502f8, boost::interprocess::mode_t mode=-2147483648) Line 76 C++ </span></p> </blockquote> <p> Second time <a class="missing wiki">CoInitializeSecurity</a> does not work </p> <blockquote class="citation"> <blockquote> <p> boost::interprocess::winapi::get_wmi_class_attribute(std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt; &amp; strValue="", const wchar_t * wmi_class=0x01595704, const wchar_t * wmi_class_var=0x01595730) Line 1457 C++ </p> </blockquote> </blockquote> <blockquote> <p> boost::interprocess::winapi::get_last_bootup_time(std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt; &amp; strValue="") Line 1554 C++ boost::interprocess::winapi::get_last_bootup_time(std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; str="") Line 1569 C++ boost::interprocess::detail::get_bootstamp(std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; s="C:\<a class="missing wiki">ProgramData</a>/boost_interprocess/", bool add=true) Line 41 C++ boost::interprocess::detail::tmp_folder(std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; tmp_name="C:\<a class="missing wiki">ProgramData</a>/boost_interprocess/") Line 108 C++ !!!boost::interprocess::detail::tmp_filename(const char * filename=0x002502f8, std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; tmp_name="C:\<a class="missing wiki">ProgramData</a>/boost_interprocess/") Line 114 C++ !!!boost::interprocess::detail::create_tmp_and_clean_old_and_get_filename(const char * filename=0x002502f8, std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; tmp_name="C:\<a class="missing wiki">ProgramData</a>/boost_interprocess/") Line 155 C++ boost::interprocess::shared_memory_object::priv_open_or_create(boost::interprocess::detail::create_enum_t type=<a class="missing wiki">DoOpen</a>, const char * filename=0x002502f8, boost::interprocess::mode_t mode=-2147483648, const boost::interprocess::permissions &amp; perm={...}) Line 181 C++ boost::interprocess::shared_memory_object::shared_memory_object(boost::interprocess::open_only_t <span class="underline">formal={...}, const char * name=0x002502f8, boost::interprocess::mode_t mode=-2147483648) Line 76 C++ </span></p> </blockquote> <p> Thanks, Patrik </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Wed, 30 Mar 2011 09:57:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5120#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5120#comment:3</guid> <description> <p> Please try Boost 1.46 or trunk code to see if this has been already fixed </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Fri, 01 Apr 2011 17:50:40 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5120#comment:4 https://svn.boost.org/trac10/ticket/5120#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> 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. </p> <p> WMI is removed in Boost 1.47 </p> Ticket Kai K. Thu, 21 Jul 2011 11:40:41 GMT <link>https://svn.boost.org/trac10/ticket/5120#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5120#comment:5</guid> <description> <p> Since WMI usage was not removed for 1.47.0 please have a look at my additions to <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5392" title="#5392: Bugs: Message queue temporary dir named &#34;Select LastBootUpTime from ... (closed: fixed)">#5392</a>! </p> </description> <category>Ticket</category> </item> </channel> </rss>