mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-20 02:40:03 +02:00
fix to access to shared memory that doesnt exist (#638)
* fix to access to shared memory that doesnt exist * fix for freeing shm and then setting hostname from API * exception error message moved to private function * refactoring to avoid allocating intermediate string
This commit is contained in:
parent
18136fed9d
commit
5c8c3ae3f3
@ -253,14 +253,15 @@ void DetectorImpl::setVirtualDetectorServers(const int numdet, const int port) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DetectorImpl::setHostname(const std::vector<std::string> &name) {
|
void DetectorImpl::setHostname(const std::vector<std::string> &name) {
|
||||||
// this check is there only to allow the previous detsizechan command
|
// do not free always to allow the previous detsize/ initialchecks command
|
||||||
if (shm()->totalNumberOfModules != 0) {
|
if (shm.exists() && shm()->totalNumberOfModules != 0) {
|
||||||
LOG(logWARNING) << "There are already module(s) in shared memory."
|
LOG(logWARNING) << "There are already module(s) in shared memory."
|
||||||
"Freeing Shared memory now.";
|
"Freeing Shared memory now.";
|
||||||
bool initialChecks = shm()->initialChecks;
|
|
||||||
freeSharedMemory();
|
freeSharedMemory();
|
||||||
|
}
|
||||||
|
// could be called after freeing shm from API
|
||||||
|
if (!shm.exists()) {
|
||||||
setupDetector();
|
setupDetector();
|
||||||
shm()->initialChecks = initialChecks;
|
|
||||||
}
|
}
|
||||||
for (const auto &hostname : name) {
|
for (const auto &hostname : name) {
|
||||||
addModule(hostname);
|
addModule(hostname);
|
||||||
|
@ -33,7 +33,7 @@ namespace sls {
|
|||||||
template <typename T> class SharedMemory {
|
template <typename T> class SharedMemory {
|
||||||
static constexpr int NAME_MAX_LENGTH = 255;
|
static constexpr int NAME_MAX_LENGTH = 255;
|
||||||
std::string name;
|
std::string name;
|
||||||
T *shared_struct{};
|
T *shared_struct{nullptr};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// moduleid of -1 creates a detector only shared memory
|
// moduleid of -1 creates a detector only shared memory
|
||||||
@ -64,8 +64,18 @@ template <typename T> class SharedMemory {
|
|||||||
unmapSharedMemory();
|
unmapSharedMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
T *operator()() { return shared_struct; }
|
T *operator()() {
|
||||||
const T *operator()() const { return shared_struct; }
|
if (shared_struct)
|
||||||
|
return shared_struct;
|
||||||
|
throw SharedMemoryError(getNoShmAccessMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
const T *operator()() const {
|
||||||
|
if (shared_struct)
|
||||||
|
return shared_struct;
|
||||||
|
throw SharedMemoryError(getNoShmAccessMessage());
|
||||||
|
}
|
||||||
|
|
||||||
std::string getName() const { return name; }
|
std::string getName() const { return name; }
|
||||||
|
|
||||||
bool exists() {
|
bool exists() {
|
||||||
@ -204,6 +214,11 @@ template <typename T> class SharedMemory {
|
|||||||
throw SharedMemoryError(msg);
|
throw SharedMemoryError(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* getNoShmAccessMessage() const {
|
||||||
|
return ("No shared memory to access. Create it first with "
|
||||||
|
"hostname or config command.");
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sls
|
} // namespace sls
|
||||||
|
Loading…
x
Reference in New Issue
Block a user