Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)) {
Expand Down Expand Up @@ -1368,12 +1375,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;
}

Expand Down Expand Up @@ -2091,7 +2100,6 @@ int main(int argc, char *argv[]) {
go2rtc_integration_cleanup();
#endif
shutdown_onvif_discovery();
cleanup_detection_resources();

// Shutdown database
log_info("Shutting down database...");
Expand Down
Loading