diff --git a/versioning/BRM/brmshmimpl.cpp b/versioning/BRM/brmshmimpl.cpp index 6b86d2d37..60bb66e31 100644 --- a/versioning/BRM/brmshmimpl.cpp +++ b/versioning/BRM/brmshmimpl.cpp @@ -45,16 +45,6 @@ BRMShmImpl::BRMShmImpl(unsigned key, off_t size, bool readOnly) : fKey(key), fSize(size), fReadOnly(readOnly) { string keyName = ShmKeys::keyToName(fKey); - - bool rootUser = true; - - //check if root-user - int user; - user = getuid(); - - if (user != 0) - rootUser = false; - string shmLocation = "/dev/shm/"; if (fSize == 0) @@ -98,43 +88,42 @@ again: try { -#if BOOST_VERSION < 104500 bi::shared_memory_object shm(bi::create_only, keyName.c_str(), bi::read_write); -#ifdef __linux__ - { - string pname = "shmLocation + keyName; - chmod(pname.c_str(), 0666); - } -#endif -#else - bi::permissions perms; - perms.set_unrestricted(); - bi::shared_memory_object shm(bi::create_only, keyName.c_str(), bi::read_write, perms); -#endif idbassert(fSize > 0); shm.truncate(fSize); fShmobj.swap(shm); } - catch (bi::interprocess_exception&) + catch (bi::interprocess_exception &b) { - bi::shared_memory_object shm(bi::open_only, keyName.c_str(), bi::read_write); + if (b.get_error_code() != bi::already_exists_error) { + ostringstream o; + o << "BRM caught an exception creating a shared memory segment: " << b.what(); + log(o.str()); + throw; + } + bi::shared_memory_object *shm = NULL; + try { + shm = new bi::shared_memory_object(bi::open_only, keyName.c_str(), bi::read_write); + } + catch (exception &e) { + ostringstream o; + o << "BRM caught an exception attaching to a shared memory segment: " << b.what(); + log(o.str()); + throw; + } off_t curSize = 0; #ifdef _MSC_VER bi::offset_t tmp = 0; shm.get_size(tmp); curSize = static_cast(tmp); #else - shm.get_size(curSize); + shm->get_size(curSize); #endif idbassert(curSize > 0); idbassert(curSize >= fSize); - fShmobj.swap(shm); + fShmobj.swap(*shm); fSize = curSize; } - catch (...) - { - throw; - } if (fReadOnly) {