From 4215a47b5c92072de975bead4854659e8d232988 Mon Sep 17 00:00:00 2001 From: Patrick LeBlanc Date: Thu, 4 Oct 2018 14:25:01 -0500 Subject: [PATCH] MCOL-520. More untested changes. Went down the list in shmkeys.h, added sane error msgs on perms errors accessing rest of the shmsegs there. Realized we probably do need 666 to the shmsegs. Also deleted a little dead code that was copy-pasted everywhere. --- dbcon/execplan/sessionmonitor.h | 4 ---- dmlproc/dmlproc.cpp | 12 ------------ procmon/main.cpp | 4 +++- tools/clearShm/main.cpp | 2 -- utils/compress/version1.cpp | 4 ---- utils/rwlock/rwlock.cpp | 24 ------------------------ versioning/BRM/brmshmimpl.cpp | 20 +++++++++++--------- versioning/BRM/mastersegmenttable.cpp | 4 +++- versioning/BRM/shmkeys.cpp | 1 - versioning/BRM/shmkeys.h | 1 - 10 files changed, 17 insertions(+), 59 deletions(-) diff --git a/dbcon/execplan/sessionmonitor.h b/dbcon/execplan/sessionmonitor.h index 42a9ec899..cf31b63b3 100644 --- a/dbcon/execplan/sessionmonitor.h +++ b/dbcon/execplan/sessionmonitor.h @@ -32,10 +32,6 @@ #include #include -#include -#include -#include - #include "calpontsystemcatalog.h" #include "sessionmanager.h" #include "shmkeys.h" diff --git a/dmlproc/dmlproc.cpp b/dmlproc/dmlproc.cpp index dec752213..5fa99be39 100644 --- a/dmlproc/dmlproc.cpp +++ b/dmlproc/dmlproc.cpp @@ -584,18 +584,6 @@ int main(int argc, char* argv[]) if (temp > 0) serverQueueSize = temp; - - bool rootUser = true; -#ifndef _MSC_VER - //check if root-user - int user; - user = getuid(); - - if (user != 0) - rootUser = false; - -#endif - //read and cleanup port before trying to use try { diff --git a/procmon/main.cpp b/procmon/main.cpp index 9c2bdfff5..90ec33238 100644 --- a/procmon/main.cpp +++ b/procmon/main.cpp @@ -73,7 +73,9 @@ bool getshm(const string &name, int size, bi::shared_memory_object &target) { bool created = false; try { - bi::shared_memory_object shm(bi::create_only, name.c_str(), bi::read_write); + bi::permissions perms; + perms.set_unrestricted(); + bi::shared_memory_object shm(bi::create_only, name.c_str(), bi::read_write, perms); created = true; shm.truncate(size); target.swap(shm); diff --git a/tools/clearShm/main.cpp b/tools/clearShm/main.cpp index 02cc0a0cf..e883bc0f6 100644 --- a/tools/clearShm/main.cpp +++ b/tools/clearShm/main.cpp @@ -220,7 +220,6 @@ int main(int argc, char** argv) shmDoit(BrmKeys.PROCESSSTATUS_SYSVKEY, "PROC_STAT "); shmDoit(BrmKeys.SYSTEMSTATUS_SYSVKEY, "SYS_STAT "); shmDoit(BrmKeys.SWITCHSTATUS_SYSVKEY, "SW_STAT "); - shmDoit(BrmKeys.STORAGESTATUS_SYSVKEY, "STORE_STAT "); shmDoit(BrmKeys.NICSTATUS_SYSVKEY, "NIC_STAT "); shmDoit(BrmKeys.DBROOTSTATUS_SYSVKEY, "DBROOT_STAT"); } @@ -239,7 +238,6 @@ int main(int argc, char** argv) semDoit(BrmKeys.PROCESSSTATUS_SYSVKEY, "PROC_STAT "); semDoit(BrmKeys.SYSTEMSTATUS_SYSVKEY, "SYS_STAT "); semDoit(BrmKeys.SWITCHSTATUS_SYSVKEY, "SW_STAT "); - semDoit(BrmKeys.STORAGESTATUS_SYSVKEY, "STORE_STAT "); semDoit(BrmKeys.NICSTATUS_SYSVKEY, "NIC_STAT "); shmDoit(BrmKeys.DBROOTSTATUS_SYSVKEY, "DBROOT_STAT"); } diff --git a/utils/compress/version1.cpp b/utils/compress/version1.cpp index 59d080022..945e2617a 100644 --- a/utils/compress/version1.cpp +++ b/utils/compress/version1.cpp @@ -188,13 +188,9 @@ void initCtlShm() } catch (bi::interprocess_exception&) { -#if BOOST_VERSION < 104500 - bi::shared_memory_object shm(bi::create_only, DecomShmName.c_str(), bi::read_write); -#else bi::permissions perms; perms.set_unrestricted(); bi::shared_memory_object shm(bi::create_only, DecomShmName.c_str(), bi::read_write, perms); -#endif shm.truncate(sizeof(CtlShmImage)); bi::mapped_region region(shm, bi::read_write); tmpptr = new (region.get_address()) CtlShmImage; diff --git a/utils/rwlock/rwlock.cpp b/utils/rwlock/rwlock.cpp index bba7f2505..abe298849 100644 --- a/utils/rwlock/rwlock.cpp +++ b/utils/rwlock/rwlock.cpp @@ -143,32 +143,11 @@ RWLockShmImpl::RWLockShmImpl(int key, bool excl) string keyName = BRM::ShmKeys::keyToName(key); fKeyString = keyName; - 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(sizeof(struct State)); fStateShm.swap(shm); bi::mapped_region region(fStateShm, bi::read_write); @@ -190,10 +169,7 @@ RWLockShmImpl::RWLockShmImpl(int key, bool excl) catch (bi::interprocess_exception&) { if (excl) - { - //don't think we can get here anymore... throw not_excl(); - } bi::shared_memory_object shm(bi::open_only, keyName.c_str(), bi::read_write); fStateShm.swap(shm); diff --git a/versioning/BRM/brmshmimpl.cpp b/versioning/BRM/brmshmimpl.cpp index 504450c99..3bf834188 100644 --- a/versioning/BRM/brmshmimpl.cpp +++ b/versioning/BRM/brmshmimpl.cpp @@ -64,12 +64,7 @@ again: #endif if (curSize == 0) throw -#if BOOST_VERSION < 104500 - bi::interprocess_exception(); - -#else bi::interprocess_exception("shm size is zero"); -#endif } catch (bi::interprocess_exception&) { @@ -87,7 +82,9 @@ again: try { - bi::shared_memory_object shm(bi::create_only, keyName.c_str(), bi::read_write); + bi::permissions perms; + perms.set_unrestricted(); + bi::shared_memory_object shm(bi::create_only, keyName.c_str(), bi::read_write, perms); idbassert(fSize > 0); shm.truncate(fSize); fShmobj.swap(shm); @@ -113,7 +110,7 @@ again: off_t curSize = 0; #ifdef _MSC_VER bi::offset_t tmp = 0; - shm.get_size(tmp); + shm->get_size(tmp); curSize = static_cast(tmp); #else shm->get_size(curSize); @@ -121,6 +118,7 @@ again: idbassert(curSize > 0); idbassert(curSize >= fSize); fShmobj.swap(*shm); + delete shm; fSize = curSize; } @@ -144,7 +142,9 @@ int BRMShmImpl::grow(unsigned newKey, off_t newSize) string oldName = fShmobj.get_name(); string keyName = ShmKeys::keyToName(newKey); - bi::shared_memory_object shm(bi::create_only, keyName.c_str(), bi::read_write); + bi::permissions perms; + perms.set_unrestricted(); + bi::shared_memory_object shm(bi::create_only, keyName.c_str(), bi::read_write, perms); shm.truncate(newSize); bi::mapped_region region(shm, bi::read_write); @@ -179,7 +179,9 @@ int BRMShmImpl::clear(unsigned newKey, off_t newSize) string oldName = fShmobj.get_name(); string keyName = ShmKeys::keyToName(newKey); - bi::shared_memory_object shm(bi::create_only, keyName.c_str(), bi::read_write); + bi::permissions perms; + perms.set_unrestricted(); + bi::shared_memory_object shm(bi::create_only, keyName.c_str(), bi::read_write, perms); shm.truncate(newSize); bi::mapped_region region(shm, bi::read_write); diff --git a/versioning/BRM/mastersegmenttable.cpp b/versioning/BRM/mastersegmenttable.cpp index 9153c112d..a2f228d58 100644 --- a/versioning/BRM/mastersegmenttable.cpp +++ b/versioning/BRM/mastersegmenttable.cpp @@ -77,7 +77,9 @@ MasterSegmentTableImpl::MasterSegmentTableImpl(int key, int size) try { - bi::shared_memory_object shm(bi::create_only, keyName.c_str(), bi::read_write); + bi::permissions perms; + perms.set_unrestricted(); + bi::shared_memory_object shm(bi::create_only, keyName.c_str(), bi::read_write, perms); shm.truncate(size); fShmobj.swap(shm); } diff --git a/versioning/BRM/shmkeys.cpp b/versioning/BRM/shmkeys.cpp index fcdf7c999..6abe149ac 100644 --- a/versioning/BRM/shmkeys.cpp +++ b/versioning/BRM/shmkeys.cpp @@ -55,7 +55,6 @@ ShmKeys::ShmKeys() PROCESSSTATUS_SYSVKEY = 0xfd000000 | BRM_UID; SYSTEMSTATUS_SYSVKEY = 0xfc000000 | BRM_UID; SWITCHSTATUS_SYSVKEY = 0xfb000000 | BRM_UID; - STORAGESTATUS_SYSVKEY = 0xfa000000 | BRM_UID; NICSTATUS_SYSVKEY = 0xf9000000 | BRM_UID; DBROOTSTATUS_SYSVKEY = 0xf8000000 | BRM_UID; DECOMSVRMUTEX_SYSVKEY = 0xf7000000 | BRM_UID; diff --git a/versioning/BRM/shmkeys.h b/versioning/BRM/shmkeys.h index bfb2cba0f..62dd67866 100644 --- a/versioning/BRM/shmkeys.h +++ b/versioning/BRM/shmkeys.h @@ -61,7 +61,6 @@ public: uint32_t PROCESSSTATUS_SYSVKEY; uint32_t SYSTEMSTATUS_SYSVKEY; uint32_t SWITCHSTATUS_SYSVKEY; - uint32_t STORAGESTATUS_SYSVKEY; uint32_t NICSTATUS_SYSVKEY; uint32_t DBROOTSTATUS_SYSVKEY; uint32_t DECOMSVRMUTEX_SYSVKEY;