remove printout prefixes
Some checks are pending
EIVE/eive-obsw/pipeline/head Build started...
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
Robin Müller 2023-02-24 01:08:26 +01:00
parent f789380343
commit 0cb7446297
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
2 changed files with 26 additions and 25 deletions

View File

@ -24,13 +24,12 @@ WatchdogTask::WatchdogTask() : fd(0) {
mode_t mode = DEFFILEMODE;
result = mkfifo(watchdog::FIFO_NAME.c_str(), mode);
if (result != 0) {
std::cerr << "eive-watchdog: Could not created named pipe at " << watchdog::FIFO_NAME
<< ", error " << errno << ": " << strerror(errno) << std::endl;
std::cerr << "Could not created named pipe at " << watchdog::FIFO_NAME << ", error " << errno
<< ": " << strerror(errno) << std::endl;
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;
std::cout << "Pipe at " << watchdog::FIFO_NAME << " created successfully" << std::endl;
#endif
}
}
@ -41,8 +40,8 @@ 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;
std::cerr << "Opening pipe " << watchdog::FIFO_NAME << "read-only failed with " << errno << ": "
<< strerror(errno) << std::endl;
return -1;
}
state = States::NOT_STARTED;
@ -54,10 +53,10 @@ int WatchdogTask::performOperation() {
}
}
if (close(fd) < 0) {
std::cerr << "eive-watchdog: Closing named pipe at " << watchdog::FIFO_NAME << "failed, error "
<< errno << ": " << strerror(errno) << std::endl;
std::cerr << "Closing named pipe at " << watchdog::FIFO_NAME << "failed, error " << errno
<< ": " << strerror(errno) << std::endl;
}
std::cout << "eive-watchdog: Finished" << std::endl;
std::cout << "Closing" << std::endl;
return 0;
}
@ -76,8 +75,8 @@ WatchdogTask::LoopResult WatchdogTask::watchdogLoop() {
return pollEvent(waiter);
}
default: {
std::cerr << "eive-watchdog: Unknown poll error at " << watchdog::FIFO_NAME << ", error "
<< errno << ": " << strerror(errno) << std::endl;
std::cerr << "Unknown poll error at " << watchdog::FIFO_NAME << ", error " << errno << ": "
<< strerror(errno) << std::endl;
break;
}
}
@ -88,8 +87,8 @@ WatchdogTask::LoopResult WatchdogTask::pollEvent(struct pollfd& waiter) {
if (waiter.revents & POLLIN) {
ssize_t readLen = read(fd, buf.data(), buf.size());
if (readLen < 0) {
std::cerr << "eive-watchdog: Read error on pipe " << watchdog::FIFO_NAME << ", error "
<< errno << ": " << strerror(errno) << std::endl;
std::cerr << "Read error on pipe " << watchdog::FIFO_NAME << ", error " << errno << ": "
<< strerror(errno) << std::endl;
return LoopResult::OK;
}
#if WATCHDOG_VERBOSE_LEVEL == 2
@ -100,7 +99,7 @@ WatchdogTask::LoopResult WatchdogTask::pollEvent(struct pollfd& waiter) {
}
} else if (waiter.revents & POLLERR) {
std::cerr << "eive-watchdog: Poll error error on pipe " << watchdog::FIFO_NAME << std::endl;
std::cerr << "Poll error error on pipe " << watchdog::FIFO_NAME << std::endl;
return LoopResult::FAULT;
} else if (waiter.revents & POLLHUP) {
// Writer closed its end
@ -142,9 +141,9 @@ int WatchdogTask::performRunningOperation() {
}
obswRunning = true;
std::cout << "eive-watchdog: Running OBSW detected.." << std::endl;
std::cout << "OBSW is running" << std::endl;
#if WATCHDOG_CREATE_FILE_IF_RUNNING == 1
std::cout << "eive-watchdog: Creating " << watchdog::RUNNING_FILE_NAME << std::endl;
std::cout << "Creating " << watchdog::RUNNING_FILE_NAME << std::endl;
if (not std::filesystem::exists(watchdog::RUNNING_FILE_NAME)) {
std::ofstream obswRunningFile(watchdog::RUNNING_FILE_NAME);
if (not obswRunningFile.good()) {
@ -160,9 +159,9 @@ int WatchdogTask::performNotRunningOperation(LoopResult type) {
// Latch prevents spam on console
if (not printNotRunningLatch) {
if (type == LoopResult::HUNG_UP) {
std::cout << "eive-watchdog: FIFO writer hung up!" << std::endl;
std::cout << "OBSW hung up" << std::endl;
} else {
std::cout << "eive-watchdog: The FIFO timed out!" << std::endl;
std::cout << "The FIFO timed out, OBSW might not be running" << std::endl;
}
printNotRunningLatch = true;
}
@ -188,7 +187,7 @@ int WatchdogTask::performNotRunningOperation(LoopResult type) {
auto timeNotRunning = std::chrono::system_clock::now() - notRunningStart.value();
if (std::chrono::duration_cast<std::chrono::milliseconds>(timeNotRunning).count() >
watchdog::MAX_NOT_RUNNING_MS) {
std::cout << "Restarting OBSW" << std::endl;
std::cout << "Restarting OBSW with systemctl" << std::endl;
std::system("systemctl restart obsw");
}
}
@ -217,7 +216,7 @@ bool WatchdogTask::stateMachine(LoopResult loopResult) {
}
case (LoopResult::SUSPEND_REQ): {
if (state == States::RUNNING or state == States::FAULTY) {
std::cout << "eive-watchdog: Suspending watchdog operations" << std::endl;
std::cout << "Received suspend request, suspending watchdog operations" << std::endl;
state = States::SUSPENDED;
}
performSuspendOperation();
@ -225,7 +224,7 @@ bool WatchdogTask::stateMachine(LoopResult loopResult) {
break;
}
case (LoopResult::CANCEL_REQ): {
std::cout << "eive-watchdog: Received cancel request, closing watchdog.." << std::endl;
std::cout << "Received cancel request, closing watchdog.." << std::endl;
return false;
}
}
@ -244,11 +243,13 @@ bool WatchdogTask::stateMachine(LoopResult loopResult) {
if (state == States::NOT_STARTED or state == States::FAULTY) {
state = States::RUNNING;
}
std::cout << "Watch request received. Restarting OBSW if not running for "
<< watchdog::MAX_NOT_RUNNING_MS / 1000 << " seconds" << std::endl;
if (loopResult == LoopResult::START_REQ) {
std::cout << "Start request without watch request received" << std::endl;
watchingObsw = false;
} else if (loopResult == LoopResult::START_WITH_WATCH_REQ) {
std::cout << "Start request with watch request received. Restarting OBSW if not "
"running for "
<< watchdog::MAX_NOT_RUNNING_MS / 1000 << " seconds" << std::endl;
watchingObsw = true;
}
performRunningOperation();

View File

@ -7,7 +7,7 @@
* It checks whether the OBSW writes to the the FIFO regularly.
*/
int main() {
std::cout << "eive-watchdog: Starting OBSW watchdog.." << std::endl;
std::cout << "Starting OBSW watchdog" << std::endl;
try {
WatchdogTask watchdogTask;
int result = watchdogTask.performOperation();
@ -15,7 +15,7 @@ int main() {
return result;
}
} catch (const std::runtime_error& e) {
std::cerr << "eive-watchdog: Run time exception " << e.what() << std::endl;
std::cerr << "Run time exception " << e.what() << std::endl;
return -1;
}
return 0;