Fixes #152 ("Handle EINTR in shared_memory_object")

This commit is contained in:
Ion Gaztañaga
2024-10-04 12:52:55 +02:00
parent 4bec5d18c0
commit 69951601fb
2 changed files with 21 additions and 5 deletions

View File

@@ -6778,11 +6778,13 @@ thank them:
You can obtain the pre-Boost 1.87 ABI #defining `BOOST_INTERPROCESS_SEGMENT_MANAGER_ABI` to `1` before including Boost.Interprocess headers.
* Fixed bugs:
* [@https://github.com/boostorg/interprocess/issues/152 GitHub #152 (['"Handle EINTR in shared_memory_object"])].
* [@https://github.com/boostorg/interprocess/issues/173 GitHub #173 (['"Managed shared memory segment value not aligned"])].
* [@https://github.com/boostorg/interprocess/issues/192 GitHub #192 (['"managed_windows_shared_memory crash on destruction"])].
* [@https://github.com/boostorg/interprocess/issues/199 GitHub #199 (['"missing/misused m_is_wide in char_wchar_holder assignment operators"])].
* [@https://github.com/boostorg/interprocess/issues/210 GitHub #210 (['"Bug in boost::interprocess::ipcdetail::sync_handles::obtain_mutex"])].
* [@https://github.com/boostorg/interprocess/issues/215 GitHub #215 (['"Alignment problem with boost/interprocess/segment_manager on SPARC 32Bit"])].
* [@https://github.com/boostorg/interprocess/issues/217 GitHub #217 (['"managed_map_file find_or_construct does not return Cache aligned memory"])].
[endsect]

View File

@@ -186,6 +186,11 @@ class shared_memory_object
file_handle_t m_handle;
mode_t m_mode;
char_wchar_holder m_filename;
#ifdef BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS
static int eintr_aware_shm_open(const char* name, int oflag, ::mode_t mode);
#endif
#endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
};
@@ -374,13 +379,13 @@ inline bool shared_memory_object::priv_open_or_create
case ipcdetail::DoOpen:
{
//No oflag addition
m_handle = shm_open(fname.c_str(), oflag, unix_perm);
m_handle = eintr_aware_shm_open(fname.c_str(), oflag, unix_perm);
}
break;
case ipcdetail::DoCreate:
{
oflag |= (O_CREAT | O_EXCL);
m_handle = shm_open(fname.c_str(), oflag, unix_perm);
m_handle = eintr_aware_shm_open(fname.c_str(), oflag, unix_perm);
if(m_handle >= 0){
::fchmod(m_handle, unix_perm);
}
@@ -392,14 +397,14 @@ inline bool shared_memory_object::priv_open_or_create
//with "O_CREAT" only we don't know if we've created or opened the shm.
while(true){
//Try to create shared memory
m_handle = shm_open(fname.c_str(), oflag | (O_CREAT | O_EXCL), unix_perm);
m_handle = eintr_aware_shm_open(fname.c_str(), oflag | (O_CREAT | O_EXCL), unix_perm);
//If successful change real permissions
if(m_handle >= 0){
::fchmod(m_handle, unix_perm);
}
//If already exists, try to open
else if(errno == EEXIST){
m_handle = shm_open(fname.c_str(), oflag, unix_perm);
m_handle = eintr_aware_shm_open(fname.c_str(), oflag, unix_perm);
//If open fails and errno tells the file does not exist
//(shm was removed between creation and opening tries), just retry
if(m_handle < 0 && errno == ENOENT){
@@ -486,6 +491,15 @@ inline void shared_memory_object::priv_close()
}
}
inline int shared_memory_object::eintr_aware_shm_open(const char* name, int oflag, ::mode_t mode)
{
int shm_open_ret;
do {
shm_open_ret = shm_open(name, oflag, mode);
} while (shm_open_ret == -1 && errno == EINTR);
return shm_open_ret;
}
#endif
//!A class that stores the name of a shared memory