This commit is contained in:
Isaac Connor 2021-08-29 09:15:40 -04:00
parent a4c079d1b3
commit 4af979c842
1 changed files with 11 additions and 13 deletions

View File

@ -199,7 +199,7 @@ bool Monitor::MonitorLink::connect() {
shared_data = (SharedData *)mem_ptr; shared_data = (SharedData *)mem_ptr;
trigger_data = (TriggerData *)((char *)shared_data + sizeof(SharedData)); trigger_data = (TriggerData *)((char *)shared_data + sizeof(SharedData));
if ( !shared_data->valid ) { if (!shared_data->valid) {
Debug(3, "Linked memory not initialised by capture daemon"); Debug(3, "Linked memory not initialised by capture daemon");
disconnect(); disconnect();
return false; return false;
@ -215,23 +215,23 @@ bool Monitor::MonitorLink::connect() {
} // end bool Monitor::MonitorLink::connect() } // end bool Monitor::MonitorLink::connect()
bool Monitor::MonitorLink::disconnect() { bool Monitor::MonitorLink::disconnect() {
if ( connected ) { if (connected) {
connected = false; connected = false;
#if ZM_MEM_MAPPED #if ZM_MEM_MAPPED
if ( mem_ptr > (void *)0 ) { if (mem_ptr > (void *)0) {
msync( mem_ptr, mem_size, MS_ASYNC ); msync(mem_ptr, mem_size, MS_ASYNC);
munmap( mem_ptr, mem_size ); munmap(mem_ptr, mem_size);
} }
if ( map_fd >= 0 ) if (map_fd >= 0)
close( map_fd ); close(map_fd);
map_fd = -1; map_fd = -1;
#else // ZM_MEM_MAPPED #else // ZM_MEM_MAPPED
struct shmid_ds shm_data; struct shmid_ds shm_data;
if ( shmctl( shm_id, IPC_STAT, &shm_data ) < 0 ) { if (shmctl(shm_id, IPC_STAT, &shm_data) < 0) {
Debug( 3, "Can't shmctl: %s", strerror(errno) ); Debug(3, "Can't shmctl: %s", strerror(errno));
return( false ); return false;
} }
shm_id = 0; shm_id = 0;
@ -247,7 +247,6 @@ bool Monitor::MonitorLink::disconnect() {
Debug(3, "Can't shmdt: %s", strerror(errno)); Debug(3, "Can't shmdt: %s", strerror(errno));
return false; return false;
} }
#endif // ZM_MEM_MAPPED #endif // ZM_MEM_MAPPED
mem_size = 0; mem_size = 0;
mem_ptr = nullptr; mem_ptr = nullptr;
@ -892,7 +891,6 @@ std::shared_ptr<Monitor> Monitor::Load(unsigned int p_id, bool load_zones, Purpo
} }
bool Monitor::connect() { bool Monitor::connect() {
if (mem_ptr != nullptr) { if (mem_ptr != nullptr) {
Warning("Already connected. Please call disconnect first."); Warning("Already connected. Please call disconnect first.");
} }
@ -1035,7 +1033,7 @@ bool Monitor::connect() {
video_store_data->size = sizeof(VideoStoreData); video_store_data->size = sizeof(VideoStoreData);
usedsubpixorder = camera->SubpixelOrder(); // Used in CheckSignal usedsubpixorder = camera->SubpixelOrder(); // Used in CheckSignal
shared_data->valid = true; shared_data->valid = true;
} else if ( !shared_data->valid ) { } else if (!shared_data->valid) {
Error("Shared data not initialised by capture daemon for monitor %s", name.c_str()); Error("Shared data not initialised by capture daemon for monitor %s", name.c_str());
return false; return false;
} }