From 6ffe80b672373b46a301228eaa2620992af52033 Mon Sep 17 00:00:00 2001 From: Maurice ONeal Date: Sat, 11 Feb 2023 20:59:19 -0500 Subject: [PATCH] v1.6.t5 Added a signal handler that will print out signal details upon receiving them. This should give up some hint to the cause of crashes for debugging reasons. The root index web page will now only be updated once. Hopefully this reduces chance of multiple instances clashing with each other. --- src/common.h | 4 +++- src/main.cpp | 46 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/common.h b/src/common.h index 9c05326..6a8f058 100644 --- a/src/common.h +++ b/src/common.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -36,7 +37,7 @@ using namespace cv; using namespace std; using namespace std::filesystem; -#define APP_VER "1.6.t4" +#define APP_VER "1.6.t5" #define APP_NAME "Motion Watch" #define TRIM_REMOVE " \n\r\t\f\v." @@ -64,6 +65,7 @@ struct shared_t string webRoot; bool init; bool skipCmd; + bool updateRoot; int cmdFinished; int clipLen; int frameGap; diff --git a/src/main.cpp b/src/main.cpp index b22254b..6e39e18 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -141,8 +141,6 @@ void recLoop(shared_t *share) { while (rdConf(share)) { - recLog("rec_loop() -- start", share); - enforceMaxLogSize(share->recLogPath, share); enforceMaxLogSize(share->detLogPath, share); @@ -151,7 +149,9 @@ void recLoop(shared_t *share) initLogFrontPages(share); - if (!exists("/tmp/mow-lock")) + recLog("rec_loop() -- start", share); + + if (!exists("/tmp/mow-lock") && share->updateRoot) { system("touch /tmp/mow-lock"); @@ -160,10 +160,8 @@ void recLoop(shared_t *share) remove("/tmp/mow-lock"); recLog("webroot page updated: " + cleanDir(share->webRoot) + "/index.html", share); - } - else - { - recLog("skipping update of the webroot page, it is busy.", share); + + share->updateRoot = false; } genHTMLul(share->outDir, share->camName, share); @@ -238,10 +236,37 @@ void recLoop(shared_t *share) } } +void sigHandler(int signal, siginfo_t *info, void *context) +{ + cerr << "received signal details: " << endl; + cerr << "-- si_pid: " << info->si_pid << endl; + cerr << "-- si_signo: " << info->si_signo << endl; + cerr << "-- si_code: " << info->si_code << endl; + cerr << "-- si_errno: " << info->si_errno << endl; + cerr << "-- si_uid: " << info->si_uid << endl; + cerr << "-- si_addr: " << info->si_addr << endl; + cerr << "-- si_status: " << info->si_status << endl; + cerr << "-- si_band: " << info->si_band << endl; + + exit(EXIT_FAILURE); +} + int main(int argc, char** argv) { struct shared_t sharedRes; + struct sigaction act = { 0 }; + + act.sa_flags = SA_SIGINFO; + act.sa_sigaction = &sigHandler; + + sigaction(SIGTERM, &act, NULL); + sigaction(SIGABRT, &act, NULL); + sigaction(SIGSEGV, &act, NULL); + sigaction(SIGILL, &act, NULL); + sigaction(SIGFPE, &act, NULL); + sigaction(SIGBUS, &act, NULL); + sharedRes.conf = parseForList("-c", argc, argv); if (parseForParam("-h", argc, argv, true) == "true") @@ -266,9 +291,10 @@ int main(int argc, char** argv) } else { - sharedRes.retCode = 0; - sharedRes.skipCmd = false; - sharedRes.init = true; + sharedRes.retCode = 0; + sharedRes.updateRoot = true; + sharedRes.skipCmd = false; + sharedRes.init = true; recLoop(&sharedRes);