Added OBSW Watchdog #67

Merged
meierj merged 20 commits from mueller/added-watchdog into develop 2021-07-31 08:51:56 +02:00
3 changed files with 17 additions and 14 deletions
Showing only changes of commit 55727accf5 - Show all commits

View File

@ -14,16 +14,7 @@
#include <filesystem>
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();

View File

@ -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;
}

View File

@ -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";
}