From 1b0899b3dab476c81ac3a7ae0dfade27364ed639 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Mar 2026 16:20:01 +0000 Subject: [PATCH] fix: isolate watchdog restart to only the timed-out camera When a single camera becomes unavailable, the watchdog timeout handler was shutting down ALL cameras and restarting them, causing all monitoring to stop. Changed watchdog() to only shut down and restart the specific camera that triggered the timeout, leaving other cameras running normally. Co-authored-by: adameat <34044711+adameat@users.noreply.github.com> Agent-Logs-Url: https://github.com/adameat/motion/sessions/7c62d05e-c203-434f-bb3e-b51887c2a343 --- src/motion.cpp | 52 +++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/src/motion.cpp b/src/motion.cpp index 6d991ffb..684960ca 100644 --- a/src/motion.cpp +++ b/src/motion.cpp @@ -352,8 +352,6 @@ void cls_motapp::ntc() /* Check for whether any cams are locked */ void cls_motapp::watchdog(uint camindx) { - int indx; - if (cam_list[camindx]->handler_running == false) { return; } @@ -367,33 +365,31 @@ void cls_motapp::watchdog(uint camindx) , _("Camera %d - Watchdog timeout.") , cam_list[camindx]->cfg->device_id); - /* Shut down all the cameras */ - for (indx=0; indxevent_stop = true; - pthread_mutex_unlock(&mutex_camlst); - pthread_mutex_unlock(&mutex_post); - pthread_mutex_unlock(&dbse->mutex_dbse); - pthread_mutex_unlock(&cam_list[indx]->stream.mutex); - - if ((cam_list[indx]->camera_type == CAMERA_TYPE_NETCAM) && - (cam_list[indx]->netcam != nullptr)) { - pthread_mutex_unlock(&cam_list[indx]->netcam->mutex); - pthread_mutex_unlock(&cam_list[indx]->netcam->mutex_pktarray); - pthread_mutex_unlock(&cam_list[indx]->netcam->mutex_transfer); - cam_list[indx]->netcam->handler_stop = true; - } - if ((cam_list[indx]->camera_type == CAMERA_TYPE_NETCAM) && - (cam_list[indx]->netcam_high != nullptr)) { - pthread_mutex_unlock(&cam_list[indx]->netcam_high->mutex); - pthread_mutex_unlock(&cam_list[indx]->netcam_high->mutex_pktarray); - pthread_mutex_unlock(&cam_list[indx]->netcam_high->mutex_transfer); - cam_list[indx]->netcam_high->handler_stop = true; - } + /* Shut down only the timed-out camera */ + cam_list[camindx]->event_stop = true; + pthread_mutex_unlock(&mutex_camlst); + pthread_mutex_unlock(&mutex_post); + pthread_mutex_unlock(&dbse->mutex_dbse); + pthread_mutex_unlock(&cam_list[camindx]->stream.mutex); + + if ((cam_list[camindx]->camera_type == CAMERA_TYPE_NETCAM) && + (cam_list[camindx]->netcam != nullptr)) { + pthread_mutex_unlock(&cam_list[camindx]->netcam->mutex); + pthread_mutex_unlock(&cam_list[camindx]->netcam->mutex_pktarray); + pthread_mutex_unlock(&cam_list[camindx]->netcam->mutex_transfer); + cam_list[camindx]->netcam->handler_stop = true; + } + if ((cam_list[camindx]->camera_type == CAMERA_TYPE_NETCAM) && + (cam_list[camindx]->netcam_high != nullptr)) { + pthread_mutex_unlock(&cam_list[camindx]->netcam_high->mutex); + pthread_mutex_unlock(&cam_list[camindx]->netcam_high->mutex_pktarray); + pthread_mutex_unlock(&cam_list[camindx]->netcam_high->mutex_transfer); + cam_list[camindx]->netcam_high->handler_stop = true; + } - cam_list[indx]->handler_shutdown(); - if (motsignal != MOTION_SIGNAL_SIGTERM) { - cam_list[indx]->handler_stop = false; /*Trigger a restart*/ - } + cam_list[camindx]->handler_shutdown(); + if (motsignal != MOTION_SIGNAL_SIGTERM) { + cam_list[camindx]->handler_stop = false; /*Trigger a restart*/ } }