fix: improve null checks and error handling in OBCameraNode methods

This commit is contained in:
ob-yalian
2026-01-13 17:23:09 +08:00
parent 979fba4f49
commit 3d8e975753
2 changed files with 43 additions and 7 deletions
+11 -2
View File
@@ -26,6 +26,7 @@
#include <sys/mman.h>
#include <unistd.h>
#include <filesystem>
#include <atomic>
#include <fstream>
#include <iomanip> // For std::put_time
@@ -35,6 +36,13 @@ std::string g_camera_name = "orbbec_camera"; // Assuming this is declared elsew
std::string g_time_domain = "global"; // Assuming this is declared elsewhere
void signalHandler(int sig) {
// Prevent recursive signal handling
static std::atomic<bool> in_signal_handler{false};
if (in_signal_handler.exchange(true)) {
// Already in signal handler, force exit immediately
_exit(sig);
}
std::cout << "Received signal: " << sig << std::endl;
if (sig == SIGINT || sig == SIGTERM) {
static int signal_count = 0;
@@ -47,8 +55,9 @@ void signalHandler(int sig) {
} else if (signal_count >= 5) {
// Force exit after second signal
std::cout << "Force exit due to multiple signals" << std::endl;
exit(sig);
_exit(sig);
}
in_signal_handler.store(false);
} else {
std::string log_dir = "Log/";
@@ -81,7 +90,7 @@ void signalHandler(int sig) {
}
log_file.close();
exit(sig); // Exit program
_exit(sig); // Use _exit instead of exit to avoid cleanup that may crash
}
}