From a35009c8ee6e8fdd49ce13ada925f4108ca6d447 Mon Sep 17 00:00:00 2001 From: Patrick LeBlanc Date: Thu, 4 Oct 2018 11:27:08 -0500 Subject: [PATCH] MCOL-520. Removed chmod stuff from MST and did a little cleaning. --- versioning/BRM/brmshmimpl.cpp | 27 +------------- versioning/BRM/mastersegmenttable.cpp | 51 +++++++++------------------ 2 files changed, 17 insertions(+), 61 deletions(-) diff --git a/versioning/BRM/brmshmimpl.cpp b/versioning/BRM/brmshmimpl.cpp index 60bb66e31..504450c99 100644 --- a/versioning/BRM/brmshmimpl.cpp +++ b/versioning/BRM/brmshmimpl.cpp @@ -45,7 +45,6 @@ BRMShmImpl::BRMShmImpl(unsigned key, off_t size, bool readOnly) : fKey(key), fSize(size), fReadOnly(readOnly) { string keyName = ShmKeys::keyToName(fKey); - string shmLocation = "/dev/shm/"; if (fSize == 0) { @@ -107,7 +106,7 @@ again: } catch (exception &e) { ostringstream o; - o << "BRM caught an exception attaching to a shared memory segment: " << b.what(); + o << "BRM caught an exception attaching to a shared memory segment (" << keyName << "): " << b.what(); log(o.str()); throw; } @@ -145,19 +144,7 @@ int BRMShmImpl::grow(unsigned newKey, off_t newSize) string oldName = fShmobj.get_name(); string keyName = ShmKeys::keyToName(newKey); -#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 shm.truncate(newSize); bi::mapped_region region(shm, bi::read_write); @@ -192,19 +179,7 @@ int BRMShmImpl::clear(unsigned newKey, off_t newSize) string oldName = fShmobj.get_name(); string keyName = ShmKeys::keyToName(newKey); -#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 shm.truncate(newSize); bi::mapped_region region(shm, bi::read_write); diff --git a/versioning/BRM/mastersegmenttable.cpp b/versioning/BRM/mastersegmenttable.cpp index 34fca9451..9153c112d 100644 --- a/versioning/BRM/mastersegmenttable.cpp +++ b/versioning/BRM/mastersegmenttable.cpp @@ -75,51 +75,32 @@ MasterSegmentTableImpl::MasterSegmentTableImpl(int key, int size) { string keyName = ShmKeys::keyToName(key); - bool rootUser = true; - - //check if root-user - int user; - user = getuid(); - - if (user != 0) - rootUser = false; - - string shmLocation = "/dev/shm/"; - 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 shm.truncate(size); fShmobj.swap(shm); } catch (bi::interprocess_exception& biex) { - bi::shared_memory_object shm(bi::open_only, keyName.c_str(), bi::read_write); -#ifdef __linux__ - { - string pname = shmLocation + keyName; - chmod(pname.c_str(), 0666); + if (biex.get_error_code() == bi::already_exists_error) { + try { + bi::shared_memory_object shm(bi::open_only, keyName.c_str(), bi::read_write); + fShmobj.swap(shm); + } + catch (exception &e) { + ostringstream o; + o << "BRM caught an exception attaching to a shared memory segment (" << keyName << "): " << e.what(); + throw; + } + } + else { + ostringstream o; + o << "BRM caught an exception creating a shared memory segment (" << keyName << "): " << biex.what(); + log(o.str()); + throw; } -#endif - fShmobj.swap(shm); } - catch (...) - { - throw; - } - bi::mapped_region region(fShmobj, bi::read_write); fMapreg.swap(region); }