From 5d66e0422a846ab0132c9b72af09d97303a9e0f5 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Thu, 26 Nov 2026 04:19:52 -0500 Subject: [PATCH 1/3] Apply suggested fix to src/core/main.c from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- src/core/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/main.c b/src/core/main.c index ca19972a9..50c5d20cf 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -2091,7 +2091,6 @@ int main(int argc, char *argv[]) { go2rtc_integration_cleanup(); #endif shutdown_onvif_discovery(); - cleanup_detection_resources(); // Shutdown database log_info("Shutting down database..."); From 15ead1cdd933ec6f37853d9e3b0687fb677628b1 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Thu, 26 Nov 2026 04:19:54 -0500 Subject: [PATCH 2/3] Apply suggested fix to src/core/main.c from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- src/core/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/main.c b/src/core/main.c index 50c5d20cf..67b3bd139 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1368,12 +1368,14 @@ int main(int argc, char *argv[]) { // are still connecting. if (!atomic_load(&running) || atomic_load(&restart_requested)) { log_info("Shutdown/restart requested before detection stream startup; aborting startup loop"); + exit_code = EXIT_SUCCESS; goto cleanup; } for (int i = 0; i < g_config.max_streams; i++) { if (!atomic_load(&running) || atomic_load(&restart_requested)) { log_info("Shutdown/restart requested during detection stream startup; aborting remaining stream startup"); + exit_code = EXIT_SUCCESS; goto cleanup; } From f3d2b80b334e4ee706a8afe8504ac8510d61ffd7 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Thu, 26 Nov 2026 04:19:57 -0500 Subject: [PATCH 3/3] Apply suggested fix to src/core/main.c from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- src/core/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/main.c b/src/core/main.c index 67b3bd139..68be809da 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -515,7 +515,7 @@ static int check_and_kill_existing_instance(const char *pid_file) { // Wait for graceful shutdown to complete before escalating to SIGKILL int timeout = SHUTDOWN_WATCHDOG_TIMEOUT_SECONDS + 30; bool still_running = true; - while (timeout-- > 0 && still_running) { + while (timeout-- > 0 && still_running && running) { if (used_pidfd) { struct pollfd pfd = { .fd = pidfd, .events = POLLIN }; int prc = poll(&pfd, 1, 1000); @@ -537,6 +537,13 @@ static int check_and_kill_existing_instance(const char *pid_file) { } } + if (!running) { + if (used_pidfd && pidfd >= 0) { + close(pidfd); + } + return -1; + } + // If still running, force kill if (timeout <= 0 && still_running && is_lightnvr_process(existing_pid)) {