From de74a15ab1df18c84647123eee552c5cfb775d82 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 12 Nov 2020 11:53:51 -0500 Subject: [PATCH] Move diag_fifo pipes in SOCKS_DIR instead of assigned Storage area. Storage areas could be a fs that cannot handle sockets or fifos like NFS. --- src/zm_fifo.cpp | 2 +- src/zm_monitor.cpp | 15 +++++++++------ src/zm_monitor.h | 4 ++-- src/zm_zone.cpp | 18 ++++++++++++------ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/zm_fifo.cpp b/src/zm_fifo.cpp index 53025f597..8743fa844 100644 --- a/src/zm_fifo.cpp +++ b/src/zm_fifo.cpp @@ -221,7 +221,7 @@ void FifoStream::setStreamStart(int monitor_id, const char * format) { } snprintf(diag_path, sizeof(diag_path), "%s/%d/%s", - monitor->getStorage()->Path(), monitor->Id(), filename); + staticConfig.PATH_SOCKS.c_str(), monitor->Id(), filename); setStreamStart(diag_path); } diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index d8e327eac..741903a0c 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -540,11 +540,14 @@ Monitor::Monitor( ReloadLinkedMonitors(p_linked_monitors); if ( config.record_diag_images ) { - diag_path_r = stringtf(config.record_diag_images_fifo ? "%s/%d/diagpipe-r.jpg" : "%s/%d/diag-r.jpg", storage->Path(), id); - diag_path_d = stringtf(config.record_diag_images_fifo ? "%s/%d/diagpipe-d.jpg" : "%s/%d/diag-d.jpg", storage->Path(), id); if ( config.record_diag_images_fifo ) { - FifoStream::fifo_create_if_missing(diag_path_r.c_str()); - FifoStream::fifo_create_if_missing(diag_path_d.c_str()); + diag_path_ref = stringtf("%s/%d/diagpipe-r.jpg", staticConfig.PATH_SOCKS.c_str(), id); + diag_path_delta = stringtf("%s/%d/diagpipe-d.jpg", staticConfig.PATH_SOCKS.c_str(), id); + FifoStream::fifo_create_if_missing(diag_path_ref.c_str()); + FifoStream::fifo_create_if_missing(diag_path_delta.c_str()); + } else { + diag_path_ref = stringtf("%s/%d/diag-r.jpg", storage->Path(), id); + diag_path_delta = stringtf("%s/%d/diag-d.jpg", storage->Path(), id); } } } // end if purpose == ANALYSIS @@ -2683,8 +2686,8 @@ unsigned int Monitor::DetectMotion(const Image &comp_image, Event::StringSet &zo ref_image.Delta(comp_image, &delta_image); if ( config.record_diag_images ) { - ref_image.WriteJpeg(diag_path_r.c_str(), config.record_diag_images_fifo); - delta_image.WriteJpeg(diag_path_d.c_str(), config.record_diag_images_fifo); + ref_image.WriteJpeg(diag_path_ref.c_str(), config.record_diag_images_fifo); + delta_image.WriteJpeg(diag_path_delta.c_str(), config.record_diag_images_fifo); } // Blank out all exclusion zones diff --git a/src/zm_monitor.h b/src/zm_monitor.h index a6d5084bb..858ea5d72 100644 --- a/src/zm_monitor.h +++ b/src/zm_monitor.h @@ -313,8 +313,8 @@ protected: Image ref_image; Image alarm_image; // Used in creating analysis images, will be initialized in Analysis Image write_image; // Used when creating snapshot images - std::string diag_path_r; - std::string diag_path_d; + std::string diag_path_ref; + std::string diag_path_delta; Purpose purpose; // What this monitor has been created to do int event_count; diff --git a/src/zm_zone.cpp b/src/zm_zone.cpp index 8fc7f88c9..8ce486821 100644 --- a/src/zm_zone.cpp +++ b/src/zm_zone.cpp @@ -113,11 +113,16 @@ void Zone::Setup( } if ( config.record_diag_images ) { - snprintf(diag_path, sizeof(diag_path), - config.record_diag_images_fifo ? "%s/diagpipe-%d-poly.jpg" : "%s/diag-%d-poly.jpg", - monitor->getStorage()->Path(), id); - if ( config.record_diag_images_fifo ) + if ( config.record_diag_images_fifo ) { + snprintf(diag_path, sizeof(diag_path), + "%s/diagpipe-%d-poly.jpg", + staticConfig.PATH_SOCKS.c_str(), id); + FifoStream::fifo_create_if_missing(diag_path); + } else { + snprintf(diag_path, sizeof(diag_path), "%s/diag-%d-poly.jpg", + monitor->getStorage()->Path(), id); + } pg_image->WriteJpeg(diag_path, config.record_diag_images_fifo); } else { diag_path[0] = 0; @@ -139,10 +144,11 @@ void Zone::RecordStats(const Event *event) { "INSERT INTO Stats SET MonitorId=%d, ZoneId=%d, EventId=%" PRIu64 ", FrameId=%d, PixelDiff=%d, AlarmPixels=%d, FilterPixels=%d, BlobPixels=%d, Blobs=%d, MinBlobSize=%d, MaxBlobSize=%d, MinX=%d, MinY=%d, MaxX=%d, MaxY=%d, Score=%d", monitor->Id(), id, event->Id(), event->Frames(), pixel_diff, alarm_pixels, alarm_filter_pixels, alarm_blob_pixels, alarm_blobs, min_blob_size, max_blob_size, alarm_box.LoX(), alarm_box.LoY(), alarm_box.HiX(), alarm_box.HiY(), score ); - if ( mysql_query(&dbconn, sql) ) { + int rc = mysql_query(&dbconn, sql); + db_mutex.unlock(); + if ( rc ) { Error("Can't insert event stats: %s", mysql_error(&dbconn)); } - db_mutex.unlock(); } // end void Zone::RecordStats( const Event *event ) bool Zone::CheckOverloadCount() {