From: Lars Op den Kamp Date: Thu, 20 Sep 2012 15:20:55 +0000 (+0200) Subject: added signal handlers to cec-client and cec-config. closes #45 X-Git-Tag: upstream/2.2.0~1^2~17^2~11 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3ccbbb19e8def4f58f8fb8336c7a743e0499c7d0;p=deb_libcec.git added signal handlers to cec-client and cec-config. closes #45 --- diff --git a/src/cec-config/cec-config.cpp b/src/cec-config/cec-config.cpp index a3d2b77..1f58ccb 100644 --- a/src/cec-config/cec-config.cpp +++ b/src/cec-config/cec-config.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include "../lib/platform/threads/mutex.h" #include "../lib/platform/util/timeutils.h" #include "../lib/implementations/CECCommandHandler.h" @@ -318,8 +319,24 @@ bool PowerOnTV(uint64_t iTimeout = 60000) return currentTvPower == CEC_POWER_STATUS_ON; } +void sighandler(int iSignal) +{ + PrintToStdOut("signal caught: %d - exiting", iSignal); + + g_parser->Close(); + UnloadLibCec(g_parser); + + exit(1); +} + int main (int UNUSED(argc), char *UNUSED(argv[])) { + if (signal(SIGINT, sighandler) == SIG_ERR) + { + PrintToStdOut("can't register sighandler"); + return -1; + } + g_callbacks.Clear(); g_config.Clear(); PrintToStdOut("=== USB-CEC Adapter Configuration ===\n"); diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index 707d7d6..f1687ba 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include "../lib/platform/os.h" #include "../lib/implementations/CECCommandHandler.h" #include "../lib/platform/util/StdString.h" @@ -1129,8 +1130,20 @@ bool ProcessCommandLineArguments(int argc, char *argv[]) return bReturn; } +void sighandler(int iSignal) +{ + PrintToStdOut("signal caught: %d - exiting", iSignal); + g_bExit = true; +} + int main (int argc, char *argv[]) { + if (signal(SIGINT, sighandler) == SIG_ERR) + { + PrintToStdOut("can't register sighandler"); + return -1; + } + g_config.Clear(); g_callbacks.Clear(); snprintf(g_config.strDeviceName, 13, "CECTester");