boost::flyweights::intermodule_holder初始化失败:权限拒绝与interprocess_exception
Boost Interprocess 共享内存初始化失败问题
问题背景
- 仅在同一进程内访问
shared_memory_object,理论上该对象应唯一,但初始化失败 - 当前目录、
$TMPDIR以及/tmp/均具备可写权限 - 堆栈跟踪中涉及的文件
/tmp/boost_interprocess/gmem/lck44132_0.000000属于其他用户,当前进程ID为38193,与文件名中的PID(44132)不匹配,怀疑存在PID复用(进程重启后PID被重新分配)的情况
堆栈跟踪信息
Catchpoint 1 (exception thrown), __cxxabiv1::__cxa_throw (obj=0x99ca40, tinfo=0x946668 <typeinfo for boost::interprocess::interprocess_exception>, dest=0x5a0f8a <boost::interprocess::interprocess_exception::~interprocess_exception()>) at ../../../../gcc-5.3.0/libstdc++-v3/libsupc++/eh_throw.cc:62 (gdb) where #0 __cxxabiv1::__cxa_throw (obj=0x99ca40, tinfo=0x946668 <typeinfo for boost::interprocess::interprocess_exception>, dest=0x5a0f8a <boost::interprocess::interprocess_exception::~interprocess_exception()>) at ../../../../gcc-5.3.0/libstdc++-v3/libsupc++/eh_throw.cc:62 #1 0x00000000005a5261 in boost::interprocess::shared_memory_object::priv_open_or_create<char> (this=0x7fffffffa200, type=boost::interprocess::ipcdetail::DoOpen, filename=0x99c930 "bip.gmem.map.44132_0.000000", mode=boost::interprocess::read_write, perm=...) at /mnt/share/boost/boost-1.80//include/boost/interprocess/shared_memory_object.hpp:425 #2 0x00000000005a1e7d in boost::interprocess::shared_memory_object::shared_memory_object (this=0x7fffffffa200, name=0x99c930 "bip.gmem.map.44132_0.000000", mode=boost::interprocess::read_write) at /mnt/share/boost/boost-1.80//include/boost/interprocess/shared_memory_object.hpp:84 #3 0x00000000005aa28b in boost::interprocess::ipcdetail::managed_open_or_create_impl<boost::interprocess::shared_memory_object, 16ul, true, false>::priv_open_or_create<char const*, boost::interprocess::ipcdetail::create_open_func<boost::interprocess::ipcdetail::basic_managed_memory_impl<char, boost::interprocess::rbtree_best_fit<boost::interprocess::ipcdetail::intermodule_singleton_mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0ul>, 0ul>, boost::interprocess::iset_index, 16ul> > > (this=0x7fffffffa3d8, type=boost::interprocess::ipcdetail::DoOpen, id=@0x7fffffffa340: 0x99c930 "bip.gmem.map.44132_0.000000", size=0, mode=boost::interprocess::read_write, addr=0x0, perm=..., construct_func=...) at /mnt/share/boost/boost-1.80//include/boost/interprocess/detail/managed_open_or_create_impl.hpp:488 #4 0x00000000005a7630 in boost::interprocess::ipcdetail::managed_open_or_create_impl<boost::interprocess::shared_memory_object, 16ul, true, false>::managed_open_or_create_impl<char const*, boost::interprocess::ipcdetail::create_open_func<boost::interprocess::ipcdetail::basic_managed_memory_impl<char, boost::interprocess::rbtree_best_fit<boost::interprocess::ipcdetail::intermodule_singleton_mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0ul>, 0ul>, boost::interprocess::iset_index, 16ul> > > (this=0x7fffffffa3d8, id=@0x7fffffffa340: 0x99c930 "bip.gmem.map.44132_0.000000", mode=boost::interprocess::read_write, addr=0x0, construct_func=...) at /mnt/share/boost/boost-1.80//include/boost/interprocess/detail/managed_open_or_create_impl.hpp:179 #5 0x00000000005a552a in boost::interprocess::ipcdetail::basic_managed_global_memory<boost::interprocess::shared_memory_object, true>::basic_managed_global_memory (this=0x7fffffffa3d0, name=0x99c930 "bip.gmem.map.44132_0.000000", addr=0x0) at /mnt/share/boost/boost-1.80//include/boost/interprocess/detail/managed_global_memory.hpp:108 #6 0x00000000005a26bf in boost::interprocess::ipcdetail::intermodule_singleton_helpers::thread_safe_global_map_dependant<boost::interprocess::ipcdetail::basic_managed_global_memory<boost::interprocess::shared_memory_object, true> >::apply_gmem_erase_logic ( filepath=0x99c8e0 "/tmp/boost_interprocess/gmem/lck44132_0.000000", filename=0x994923 "lck44132_0.000000") at /mnt/share/boost/boost-1.80//include/boost/interprocess/detail/portable_intermodule_singleton.hpp:171 #7 0x00000000005a57a8 in boost::interprocess::ipcdetail::for_each_file_in_dir<void (*)(char const*, char const*)> ( dir=0x994840 "/tmp/boost_interprocess/gmem", f=0x5a25e7 <boost::interprocess::ipcdetail::intermodule_singleton_helpers::thread_safe_global_map_dependant<boost::interprocess::ipcdetail::basic_managed_global_memory<boost::interprocess::shared_memory_object, true> >::apply_gmem_erase_logic(char const*, char const*)>) at /mnt/share/boost/boost-1.80//include/boost/interprocess/detail/os_file_functions.hpp:804 #8 0x00000000005a283d in boost::interprocess::ipcdetail::intermodule_singleton_helpers::thread_safe_global_map_dependant<boost::interprocess::ipcdetail::basic_managed_global_memory<boost::interprocess::shared_memory_object, true> >::remove_old_gmem () at /mnt/share/boost/boost-1.80//include/boost/interprocess/detail/portable_intermodule_singleton.hpp:198 #9 0x00000000005b9eab in boost::interprocess::ipcdetail::intermodule_singleton_common<boost::interprocess::ipcdetail::basic_managed_global_memory<boost::interprocess::shared_memory_object, true> >::initialize_global_map_handle () at /mnt/share/boost/boost-1.80//include/boost/interprocess/detail/intermodule_singleton_common.hpp:237 #10 0x00000000005b588f in boost::interprocess::ipcdetail::intermodule_singleton_common<boost::interprocess::ipcdetail::basic_managed_global_memory<boost::interprocess::shared_memory_object, true> >::initialize_singleton_logic (ptr=@0x97ba80: 0x0, this_module_singleton_initialized=@0x97ba88: 1, constructor=0x5b59e7 <boost::interprocess::ipcdetail::intermodule_singleton_impl<boost::flyweights::detail::flyweight_core<boost::flyweights::detail::default_value_policy<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, mpl_::na, boost::flyweights::refcounted, boost::flyweights::hashed_factory<mpl_::na, mpl_::na, mpl_::na, 0>, boost::flyweights::no_locking, boost::flyweights::intermodule_holder>::holder_arg, true, false, boost::interprocess::ipcdetail::basic_managed_global_memory<boost::interprocess::shared_memory_object, true> >::singleton_constructor(boost::interprocess::ipcdetail::basic_managed_global_memory<boost::interprocess::shared_memory_object, true>&)>, phoenix=false) at /mnt/share/boost/boost-1.80//include/boost/interprocess/detail/intermodule_singleton_common.hpp:127 #11 0x00000000005b21e2 in boost::interprocess::ipcdetail::intermodule_singleton_impl<boost::flyweights::detail::flyweight_core<boost::flyweights::detail::default_value_policy<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, mpl_::na, boost::flyweights::refcounted, boost::flyweights::hashed_factory<mpl_::na, mpl_::na, mpl_::na, 0>, boost::flyweights::no_locking, boost::flyweights::intermodule_holder>::holder_arg, true, false, boost::interprocess::ipcdetail::basic_managed_global_memory<boost::interprocess::shared_memory_object, true> >::atentry_work () at /mnt/share/boost/boost-1.80//include/boost/interprocess/detail/intermodule_singleton_common.hpp:345 #12 0x00000000005aee02 in boost::interprocess::ipcdetail::intermodule_singleton_impl<boost::flyweights::detail::flyweight_core<boost::flyweights::detail::default_value_policy<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, mpl_::na, boost::flyweights::refcounted, boost::flyweights::hashed_factory<mpl_::na, mpl_::na, mpl_::na, 0>, boost::flyweights::no_locking, boost::flyweights::intermodule_holder>::holder_arg, true, false, boost::interprocess::ipcdetail::basic_managed_global_memory<boost::interprocess::shared_memory_object, true> >::get () at /mnt/share/boost/boost-1.80//include/boost/interprocess/detail/intermodule_singleton_common.hpp:335 #13 0x00000000005aaf81 in boost::flyweights::detail::flyweight_core<boost::flyweights::detail::default_value_policy<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, mpl_::na, boost::flyweights::refcounted, boost::flyweights::hashed_factory<mpl_::na, mpl_::na, mpl_::na, 0>, boost::flyweights::no_locking, boost::flyweights::intermodule_holder>::init () at /mnt/share/boost/boost-1.80//include/boost/flyweight/detail/flyweight_core.hpp:112 #14 0x000000000059de56 in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at /mnt/share/boost/boost-1.80//include/boost/flyweight/detail/flyweight_core.hpp:278 #15 0x000000000059f46b in _GLOBAL__sub_I_messagehandler.cc(void) () at src/framework/src/messagehandler.cc:2516 #16 0x00000000007fe79d in __libc_csu_init () #17 0x00002aaaabbbf4e5 in __libc_start_main () from /lib64/libc.so.6 #18 0x00000000005901ae in _start ()
问题分析
从堆栈跟踪可以看出,失败发生在Boost Interprocess初始化全局共享内存映射时:程序尝试打开名为bip.gmem.map.44132_0.000000的共享内存对象,而该对象关联的锁文件/tmp/boost_interprocess/gmem/lck44132_0.000000属于其他用户。由于当前进程PID为38193,与文件名中的44132不符,说明是PID复用导致的问题:之前运行过的PID为44132的进程异常退出,未清理Boost Interprocess生成的共享内存和锁文件,后续PID被重新分配给当前进程,但当前进程没有权限访问属于其他用户的遗留文件,最终抛出interprocess_exception。
内容的提问来源于stack exchange,提问作者Frank Puck
相关产品推荐
相关产品推荐

