1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-27 21:01:50 +03:00

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.
This commit is contained in:
Patrick LeBlanc
2018-10-04 14:25:01 -05:00
parent a35009c8ee
commit 4215a47b5c
10 changed files with 17 additions and 59 deletions

View File

@ -32,10 +32,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <boost/interprocess/sync/interprocess_semaphore.hpp>
#include "calpontsystemcatalog.h" #include "calpontsystemcatalog.h"
#include "sessionmanager.h" #include "sessionmanager.h"
#include "shmkeys.h" #include "shmkeys.h"

View File

@ -584,18 +584,6 @@ int main(int argc, char* argv[])
if (temp > 0) if (temp > 0)
serverQueueSize = temp; 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 //read and cleanup port before trying to use
try try
{ {

View File

@ -73,7 +73,9 @@ bool getshm(const string &name, int size, bi::shared_memory_object &target) {
bool created = false; bool created = false;
try 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; created = true;
shm.truncate(size); shm.truncate(size);
target.swap(shm); target.swap(shm);

View File

@ -220,7 +220,6 @@ int main(int argc, char** argv)
shmDoit(BrmKeys.PROCESSSTATUS_SYSVKEY, "PROC_STAT "); shmDoit(BrmKeys.PROCESSSTATUS_SYSVKEY, "PROC_STAT ");
shmDoit(BrmKeys.SYSTEMSTATUS_SYSVKEY, "SYS_STAT "); shmDoit(BrmKeys.SYSTEMSTATUS_SYSVKEY, "SYS_STAT ");
shmDoit(BrmKeys.SWITCHSTATUS_SYSVKEY, "SW_STAT "); shmDoit(BrmKeys.SWITCHSTATUS_SYSVKEY, "SW_STAT ");
shmDoit(BrmKeys.STORAGESTATUS_SYSVKEY, "STORE_STAT ");
shmDoit(BrmKeys.NICSTATUS_SYSVKEY, "NIC_STAT "); shmDoit(BrmKeys.NICSTATUS_SYSVKEY, "NIC_STAT ");
shmDoit(BrmKeys.DBROOTSTATUS_SYSVKEY, "DBROOT_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.PROCESSSTATUS_SYSVKEY, "PROC_STAT ");
semDoit(BrmKeys.SYSTEMSTATUS_SYSVKEY, "SYS_STAT "); semDoit(BrmKeys.SYSTEMSTATUS_SYSVKEY, "SYS_STAT ");
semDoit(BrmKeys.SWITCHSTATUS_SYSVKEY, "SW_STAT "); semDoit(BrmKeys.SWITCHSTATUS_SYSVKEY, "SW_STAT ");
semDoit(BrmKeys.STORAGESTATUS_SYSVKEY, "STORE_STAT ");
semDoit(BrmKeys.NICSTATUS_SYSVKEY, "NIC_STAT "); semDoit(BrmKeys.NICSTATUS_SYSVKEY, "NIC_STAT ");
shmDoit(BrmKeys.DBROOTSTATUS_SYSVKEY, "DBROOT_STAT"); shmDoit(BrmKeys.DBROOTSTATUS_SYSVKEY, "DBROOT_STAT");
} }

View File

@ -188,13 +188,9 @@ void initCtlShm()
} }
catch (bi::interprocess_exception&) 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; bi::permissions perms;
perms.set_unrestricted(); perms.set_unrestricted();
bi::shared_memory_object shm(bi::create_only, DecomShmName.c_str(), bi::read_write, perms); bi::shared_memory_object shm(bi::create_only, DecomShmName.c_str(), bi::read_write, perms);
#endif
shm.truncate(sizeof(CtlShmImage)); shm.truncate(sizeof(CtlShmImage));
bi::mapped_region region(shm, bi::read_write); bi::mapped_region region(shm, bi::read_write);
tmpptr = new (region.get_address()) CtlShmImage; tmpptr = new (region.get_address()) CtlShmImage;

View File

@ -143,32 +143,11 @@ RWLockShmImpl::RWLockShmImpl(int key, bool excl)
string keyName = BRM::ShmKeys::keyToName(key); string keyName = BRM::ShmKeys::keyToName(key);
fKeyString = keyName; fKeyString = keyName;
bool rootUser = true;
//check if root-user
int user;
user = getuid();
if (user != 0)
rootUser = false;
string shmLocation = "/dev/shm/";
try 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; bi::permissions perms;
perms.set_unrestricted(); perms.set_unrestricted();
bi::shared_memory_object shm(bi::create_only, keyName.c_str(), bi::read_write, perms); bi::shared_memory_object shm(bi::create_only, keyName.c_str(), bi::read_write, perms);
#endif
shm.truncate(sizeof(struct State)); shm.truncate(sizeof(struct State));
fStateShm.swap(shm); fStateShm.swap(shm);
bi::mapped_region region(fStateShm, bi::read_write); bi::mapped_region region(fStateShm, bi::read_write);
@ -190,10 +169,7 @@ RWLockShmImpl::RWLockShmImpl(int key, bool excl)
catch (bi::interprocess_exception&) catch (bi::interprocess_exception&)
{ {
if (excl) if (excl)
{
//don't think we can get here anymore...
throw not_excl(); throw not_excl();
}
bi::shared_memory_object shm(bi::open_only, keyName.c_str(), bi::read_write); bi::shared_memory_object shm(bi::open_only, keyName.c_str(), bi::read_write);
fStateShm.swap(shm); fStateShm.swap(shm);

View File

@ -64,12 +64,7 @@ again:
#endif #endif
if (curSize == 0) throw if (curSize == 0) throw
#if BOOST_VERSION < 104500
bi::interprocess_exception();
#else
bi::interprocess_exception("shm size is zero"); bi::interprocess_exception("shm size is zero");
#endif
} }
catch (bi::interprocess_exception&) catch (bi::interprocess_exception&)
{ {
@ -87,7 +82,9 @@ again:
try 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); idbassert(fSize > 0);
shm.truncate(fSize); shm.truncate(fSize);
fShmobj.swap(shm); fShmobj.swap(shm);
@ -113,7 +110,7 @@ again:
off_t curSize = 0; off_t curSize = 0;
#ifdef _MSC_VER #ifdef _MSC_VER
bi::offset_t tmp = 0; bi::offset_t tmp = 0;
shm.get_size(tmp); shm->get_size(tmp);
curSize = static_cast<off_t>(tmp); curSize = static_cast<off_t>(tmp);
#else #else
shm->get_size(curSize); shm->get_size(curSize);
@ -121,6 +118,7 @@ again:
idbassert(curSize > 0); idbassert(curSize > 0);
idbassert(curSize >= fSize); idbassert(curSize >= fSize);
fShmobj.swap(*shm); fShmobj.swap(*shm);
delete shm;
fSize = curSize; fSize = curSize;
} }
@ -144,7 +142,9 @@ int BRMShmImpl::grow(unsigned newKey, off_t newSize)
string oldName = fShmobj.get_name(); string oldName = fShmobj.get_name();
string keyName = ShmKeys::keyToName(newKey); 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); shm.truncate(newSize);
bi::mapped_region region(shm, bi::read_write); 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 oldName = fShmobj.get_name();
string keyName = ShmKeys::keyToName(newKey); 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); shm.truncate(newSize);
bi::mapped_region region(shm, bi::read_write); bi::mapped_region region(shm, bi::read_write);

View File

@ -77,7 +77,9 @@ MasterSegmentTableImpl::MasterSegmentTableImpl(int key, int size)
try 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); shm.truncate(size);
fShmobj.swap(shm); fShmobj.swap(shm);
} }

View File

@ -55,7 +55,6 @@ ShmKeys::ShmKeys()
PROCESSSTATUS_SYSVKEY = 0xfd000000 | BRM_UID; PROCESSSTATUS_SYSVKEY = 0xfd000000 | BRM_UID;
SYSTEMSTATUS_SYSVKEY = 0xfc000000 | BRM_UID; SYSTEMSTATUS_SYSVKEY = 0xfc000000 | BRM_UID;
SWITCHSTATUS_SYSVKEY = 0xfb000000 | BRM_UID; SWITCHSTATUS_SYSVKEY = 0xfb000000 | BRM_UID;
STORAGESTATUS_SYSVKEY = 0xfa000000 | BRM_UID;
NICSTATUS_SYSVKEY = 0xf9000000 | BRM_UID; NICSTATUS_SYSVKEY = 0xf9000000 | BRM_UID;
DBROOTSTATUS_SYSVKEY = 0xf8000000 | BRM_UID; DBROOTSTATUS_SYSVKEY = 0xf8000000 | BRM_UID;
DECOMSVRMUTEX_SYSVKEY = 0xf7000000 | BRM_UID; DECOMSVRMUTEX_SYSVKEY = 0xf7000000 | BRM_UID;

View File

@ -61,7 +61,6 @@ public:
uint32_t PROCESSSTATUS_SYSVKEY; uint32_t PROCESSSTATUS_SYSVKEY;
uint32_t SYSTEMSTATUS_SYSVKEY; uint32_t SYSTEMSTATUS_SYSVKEY;
uint32_t SWITCHSTATUS_SYSVKEY; uint32_t SWITCHSTATUS_SYSVKEY;
uint32_t STORAGESTATUS_SYSVKEY;
uint32_t NICSTATUS_SYSVKEY; uint32_t NICSTATUS_SYSVKEY;
uint32_t DBROOTSTATUS_SYSVKEY; uint32_t DBROOTSTATUS_SYSVKEY;
uint32_t DECOMSVRMUTEX_SYSVKEY; uint32_t DECOMSVRMUTEX_SYSVKEY;