Boost C++ Libraries: Ticket #7928: boost::interprocess::shared_memory_object creation cause infinite loop https://svn.boost.org/trac10/ticket/7928 <p> Call of <strong>boost::interprocess::shared_memory_object</strong> creation cause infinite loop in case there is: boost::interprocess::shared_memory_object shm ( boost::interprocess::open_or_create, "some-name", boost::interprocess::read_write, 256); I dig inside of code and it happen in file: </p> <p> <strong>boost/interprocess/shared_memory_object.hpp</strong> </p> <blockquote> <p> this function : </p> </blockquote> <p> inline <strong>bool</strong> <strong>shared_memory_object::priv_open_or_create</strong> </p> <blockquote> <p> (ipcdetail::create_enum_t type, </p> <blockquote> <p> const char *filename, mode_t mode, const permissions &amp;perm) </p> </blockquote> </blockquote> <p> { ..... </p> <p> in switch/case: .... case <strong>ipcdetail::<a class="missing wiki">DoOpenOrCreate</a></strong>: </p> <blockquote> <p> { </p> <blockquote> <p> oflag |= O_CREAT; <em>We need a loop to change permissions correctly using fchmod, since </em>with "O_CREAT only" shm_open we don't know if we've created or opened the file. while(1){ </p> <blockquote> <p> m_handle = shm_open(m_filename.c_str(), oflag, unix_perm); if(m_handle &gt;= 0){ </p> <blockquote> <p> ::fchmod(m_handle, unix_perm); break; </p> </blockquote> <p> } else if(errno == EEXIST){ </p> <blockquote> <table class="wiki"> <tr>if((m_handle = shm_open(m_filename.c_str(), oflag, unix_perm)) &gt;= 0 <td> errno != ENOENT){ </td></tr></table> <blockquote> <p> break; </p> </blockquote> <p> } </p> </blockquote> <p> } </p> </blockquote> <p> } </p> </blockquote> <p> } </p> </blockquote> <p> ... as you can see there is a while and this while will remain infinite in case of any other errno then: "<strong>EEXIST</strong>" </p> <p> ... there are 9 different errors possible in case of shm_open() call, so they should be handled, in my case it was EACCES what brick my testing. </p> <p> I'm testing it on <strong>1.50</strong> but saw <strong>1.52</strong> have the same code ..... </p> <p> Reagards </p> <p> Ladislav Sopko lsopko@… </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7928 Trac 1.4.3 Ion Gaztañaga Sun, 10 Feb 2013 11:17:14 GMT <link>https://svn.boost.org/trac10/ticket/7928#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7928#comment:1</guid> <description> <p> Thanks for the report. I'll change the loop so that retries are only done if creation exactly returns EEXIST and opening returns ENOENT. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Sun, 10 Feb 2013 11:19:00 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7928#comment:2 https://svn.boost.org/trac10/ticket/7928#comment:2 <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> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/82802" title="Fixes #7928">[82802]</a>) Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7928" title="#7928: Bugs: boost::interprocess::shared_memory_object creation cause infinite loop (closed: fixed)">#7928</a> </p> Ticket Ion Gaztañaga Sun, 10 Feb 2013 11:20:49 GMT <link>https://svn.boost.org/trac10/ticket/7928#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7928#comment:3</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/82803" title="Fixes #7928">[82803]</a>) Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7928" title="#7928: Bugs: boost::interprocess::shared_memory_object creation cause infinite loop (closed: fixed)">#7928</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Sun, 10 Feb 2013 11:21:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7928#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7928#comment:4</guid> <description> <p> Can you test if your problem was solved? Thanks </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 11 Feb 2013 07:30:40 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7928#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7928#comment:5</guid> <description> <p> I'll test it asap. Thx </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 12 Feb 2013 14:21:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7928#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7928#comment:6</guid> <description> <p> It worked, but in which version of boost i can have this patch? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Tue, 12 Feb 2013 15:09:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7928#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7928#comment:7</guid> <description> <p> I'm afraid it won't be out until Boost 1.54. We have not release date yet for that version. </p> </description> <category>Ticket</category> </item> </channel> </rss>