From 55727accf5e35f81371214f74ac18faaa9a33e95 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 29 Jul 2021 11:59:32 +0200 Subject: [PATCH] minor tweaks --- watchdog/Watchdog.cpp | 18 ++++++++---------- watchdog/main.cpp | 11 ++++++++--- watchdog/watchdogConf.h.in | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/watchdog/Watchdog.cpp b/watchdog/Watchdog.cpp index e66a2545..f4f8c03c 100644 --- a/watchdog/Watchdog.cpp +++ b/watchdog/Watchdog.cpp @@ -14,16 +14,7 @@ #include - WatchdogTask::WatchdogTask (): fd(0) { - -} - -WatchdogTask::~WatchdogTask() { - -} - -int WatchdogTask::performOperation() { int result = 0; // Only create the FIFO if it does not exist yet if(not std::filesystem::exists(watchdog::FIFO_NAME)) { @@ -34,20 +25,27 @@ int WatchdogTask::performOperation() { std::cerr << "eive-watchdog: Could not created named pipe at " << watchdog::FIFO_NAME << ", error " << errno << ": " << strerror(errno) << std::endl; - return -2; + throw std::runtime_error("eive-watchdog: FIFO creation failed"); } #if WATCHDOG_VERBOSE_LEVEL >= 1 std::cout << "eive-watchdog: Pipe at " << watchdog::FIFO_NAME << " created successfully" << std::endl; #endif } +} +WatchdogTask::~WatchdogTask() { + +} + +int WatchdogTask::performOperation() { // Open FIFO read only and non-blocking fd = open(watchdog::FIFO_NAME.c_str(), O_RDONLY | O_NONBLOCK); if(fd < 0) { std::cerr << "eive-watchdog: Opening pipe " << watchdog::FIFO_NAME << "read-only failed with " << errno << ": " << strerror(errno) << std::endl; } + state = States::RUNNING; while(true) { WatchdogTask::LoopResult loopResult = watchdogLoop(); diff --git a/watchdog/main.cpp b/watchdog/main.cpp index eea608f1..a1ae3ae8 100644 --- a/watchdog/main.cpp +++ b/watchdog/main.cpp @@ -7,9 +7,14 @@ * It checks whether the OBSW writes to the the FIFO regularly. */ int main() { - std::cout << "Starting OBSW watchdog.." << std::endl; - WatchdogTask watchdogTask; - watchdogTask.performOperation(); + std::cout << "eive-watchdog: Starting OBSW watchdog.." << std::endl; + try { + WatchdogTask watchdogTask; + watchdogTask.performOperation(); + } + catch(const std::runtime_error& e) { + std::cerr << "eive-watchdog: Run time exception " << e.what() << std::endl; + } return 0; } diff --git a/watchdog/watchdogConf.h.in b/watchdog/watchdogConf.h.in index 8b9a0afc..daa9f248 100644 --- a/watchdog/watchdogConf.h.in +++ b/watchdog/watchdogConf.h.in @@ -10,7 +10,7 @@ namespace watchdog { static constexpr int TIMEOUT_MS = 10 * 1000; -const std::string FIFO_NAME = "/tmp/obsw-watchdog"; +const std::string FIFO_NAME = "/tmp/watchdog-pipe"; const std::string RUNNING_FILE_NAME = "/tmp/obsw-running"; }