minor tweaks

This commit is contained in:
Robin Müller 2021-07-29 11:59:32 +02:00
parent 59bcf6cec2
commit 55727accf5
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
3 changed files with 17 additions and 14 deletions

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