shm: error on duplicate region IDs

This commit is contained in:
Alexey Rybalchenko
2022-10-04 12:15:21 +02:00
committed by Dennis Klein
parent 9a25c4d28a
commit ed364a4857
2 changed files with 33 additions and 6 deletions

View File

@@ -146,7 +146,7 @@ struct UnmanagedRegion
LOG(debug) << "Successfully zeroed free memory of region " << id << ".";
}
if (fControlling) {
if (fControlling && created) {
Register(shmId, cfg);
}
@@ -160,6 +160,13 @@ struct UnmanagedRegion
UnmanagedRegion& operator=(const UnmanagedRegion&) = delete;
UnmanagedRegion& operator=(UnmanagedRegion&&) = delete;
void BecomeController(RegionConfig& cfg)
{
fControlling = true;
fLinger = cfg.linger;
fRemoveOnDestruction = cfg.removeOnDestruction;
}
void Zero()
{
memset(fRegion.get_address(), 0x00, fRegion.get_size());
@@ -263,10 +270,14 @@ struct UnmanagedRegion
EventCounter* eventCounter = mngSegment.find_or_construct<EventCounter>(unique_instance)(0);
bool newShmRegionCreated = shmRegions->emplace(cfg.id.value(), RegionInfo(cfg.path.c_str(), cfg.creationFlags, cfg.userFlags, cfg.size, alloc)).second;
if (newShmRegionCreated) {
(eventCounter->fCount)++;
auto it = shmRegions->find(cfg.id.value());
if (it != shmRegions->end()) {
LOG(error) << "Unmanaged Region with id " << cfg.id.value() << " has already been registered. Only unique IDs per session are allowed.";
throw TransportError(tools::ToString("Unmanaged Region with id ", cfg.id.value(), " has already been registered. Only unique IDs per session are allowed."));
}
shmRegions->emplace(cfg.id.value(), RegionInfo(cfg.path.c_str(), cfg.creationFlags, cfg.userFlags, cfg.size, alloc)).second;
(eventCounter->fCount)++;
}
void SetCallbacks(RegionCallback callback, RegionBulkCallback bulkCallback)