diff --git a/procmon/main.cpp b/procmon/main.cpp index 90ec33238..fce730c35 100644 --- a/procmon/main.cpp +++ b/procmon/main.cpp @@ -96,7 +96,8 @@ bool getshm(const string &name, int size, bi::shared_memory_object &target) { } else { ostringstream os; - os << "ProcMon failed to create the 'proc stat' shared mem segment, got " << biex.what(); + os << "ProcMon failed to create the '" << name << "' shared mem segment, got " << biex.what() << "."; + os << " Check the permissions on /dev/shm; should be 1777"; log.writeLog(__LINE__, os.str(), LOG_TYPE_CRITICAL); exit(1); } diff --git a/utils/rwlock/rwlock.cpp b/utils/rwlock/rwlock.cpp index abe298849..d042b905e 100644 --- a/utils/rwlock/rwlock.cpp +++ b/utils/rwlock/rwlock.cpp @@ -166,13 +166,25 @@ RWLockShmImpl::RWLockShmImpl(int key, bool excl) new (&fState->sems[RWLock::READERS]) bi::interprocess_semaphore(0); new (&fState->sems[RWLock::WRITERS]) bi::interprocess_semaphore(0); } - catch (bi::interprocess_exception&) + catch (bi::interprocess_exception &e) { - if (excl) + if (e.get_error_code() == bi::security_error) { + cerr << "RWLock: Failed to create the lock. Check perms on /dev/shm; should be 1777" << endl; + throw; + } + if (e.get_error_code() == bi::already_exists_error && excl) throw not_excl(); + if (e.get_error_code() != bi::already_exists_error) + throw; - bi::shared_memory_object shm(bi::open_only, keyName.c_str(), bi::read_write); - fStateShm.swap(shm); + try { + bi::shared_memory_object shm(bi::open_only, keyName.c_str(), bi::read_write); + fStateShm.swap(shm); + } + catch (exception &e) { + cerr << "RWLock failed to attach to the " << keyName << " shared mem segment, got " << e.what() << endl; + throw; + } bi::mapped_region region(fStateShm, bi::read_write); fRegion.swap(region); fState = static_cast(fRegion.get_address());