From a5ff4d8ef2974b3cebbc8ea862702b154291fa92 Mon Sep 17 00:00:00 2001 From: MrDave Date: Sun, 20 Dec 2020 13:03:02 -0700 Subject: [PATCH] Add watchdog kill as parameter --- src/conf.cpp | 24 ++++++++++++++++++++++++ src/conf.hpp | 1 + src/motionplus.cpp | 4 ++-- src/motionplus.hpp | 1 - 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/conf.cpp b/src/conf.cpp index d3d0e244..fd6d34ca 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -93,6 +93,10 @@ struct ctx_parm config_parms[] = { "# Timeout in seconds for thread response.", 0, PARM_TYP_INT,PARM_CAT_01,WEBUI_LEVEL_LIMITED}, { + "watchdog_kill", + "# Timeout before forcefully killing the thread.", + 0, PARM_TYP_INT,PARM_CAT_01,WEBUI_LEVEL_LIMITED}, + { "v4l2_device", "# Video device (e.g. /dev/video0) to be used for capturing.", 0,PARM_TYP_STRING,PARM_CAT_01,WEBUI_LEVEL_ADVANCED @@ -1080,6 +1084,25 @@ static void conf_edit_watchdog_tmo(struct ctx_cam *cam, std::string &parm, enum MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO,"%s:%s","watchdog_tmo",_("watchdog_tmo")); } +static void conf_edit_watchdog_kill(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) +{ + int parm_in; + if (pact == PARM_ACT_DFLT){ + cam->conf->watchdog_kill = 10; + } else if (pact == PARM_ACT_SET){ + parm_in = atoi(parm.c_str()); + if (parm_in < 1) { + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid watchdog kill timeout %d"),parm_in); + } else { + cam->conf->watchdog_kill = parm_in; + } + } else if (pact == PARM_ACT_GET){ + parm = std::to_string(cam->conf->watchdog_kill); + } + return; + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO,"%s:%s","watchdog_kill",_("watchdog_kill")); +} + static void conf_edit_v4l2_device(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { if (pact == PARM_ACT_DFLT) { @@ -3130,6 +3153,7 @@ static void conf_edit_cat01(struct ctx_cam *cam, std::string parm_nm, std::strin } else if (parm_nm == "camera_id"){ conf_edit_camera_id(cam, parm_val, pact); } else if (parm_nm == "target_dir"){ conf_edit_target_dir(cam, parm_val, pact); } else if (parm_nm == "watchdog_tmo"){ conf_edit_watchdog_tmo(cam, parm_val, pact); + } else if (parm_nm == "watchdog_kill"){ conf_edit_watchdog_kill(cam, parm_val, pact); } else if (parm_nm == "v4l2_device"){ conf_edit_v4l2_device(cam, parm_val, pact); } else if (parm_nm == "v4l2_params"){ conf_edit_v4l2_params(cam, parm_val, pact); } else if (parm_nm == "netcam_url"){ conf_edit_netcam_url(cam, parm_val, pact); diff --git a/src/conf.hpp b/src/conf.hpp index 63eeb931..68613feb 100644 --- a/src/conf.hpp +++ b/src/conf.hpp @@ -32,6 +32,7 @@ std::string camera_dir; std::string target_dir; int watchdog_tmo; + int watchdog_kill; /* Capture device configuration parameters */ std::string v4l2_device; diff --git a/src/motionplus.cpp b/src/motionplus.cpp index f52bf877..9324c2f3 100644 --- a/src/motionplus.cpp +++ b/src/motionplus.cpp @@ -480,7 +480,7 @@ static void motion_watchdog(struct ctx_motapp *motapp, int indx) motapp->cam_list[indx]->finish_cam = TRUE; } - if (motapp->cam_list[indx]->watchdog == WATCHDOG_KILL) { + if (motapp->cam_list[indx]->watchdog == (0 - motapp->cam_list[indx]->conf->watchdog_kill) ) { MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO ,_("Thread %d - Watchdog timeout did NOT restart, killing it!") , motapp->cam_list[indx]->threadnr); @@ -495,7 +495,7 @@ static void motion_watchdog(struct ctx_motapp *motapp, int indx) pthread_cancel(motapp->cam_list[indx]->thread_id); } - if (motapp->cam_list[indx]->watchdog < WATCHDOG_KILL) { + if (motapp->cam_list[indx]->watchdog < (0 - motapp->cam_list[indx]->conf->watchdog_kill)) { MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO ,_("Thread %d - Watchdog kill!") , motapp->cam_list[indx]->threadnr); diff --git a/src/motionplus.hpp b/src/motionplus.hpp index 3d4061de..ff7724e5 100644 --- a/src/motionplus.hpp +++ b/src/motionplus.hpp @@ -87,7 +87,6 @@ struct ctx_v4l2cam; #define THRESHOLD_TUNE_LENGTH 256 #define MISSING_FRAMES_TIMEOUT 30 /* Frame count before grey lost image is used */ -#define WATCHDOG_KILL -10 /* 10 sec grace period before calling thread cancel */ /* Filetype defines */ #define FTYPE_IMAGE 1