remove printout prefixes
This commit is contained in:
parent
f789380343
commit
0cb7446297
@ -24,13 +24,12 @@ WatchdogTask::WatchdogTask() : fd(0) {
|
|||||||
mode_t mode = DEFFILEMODE;
|
mode_t mode = DEFFILEMODE;
|
||||||
result = mkfifo(watchdog::FIFO_NAME.c_str(), mode);
|
result = mkfifo(watchdog::FIFO_NAME.c_str(), mode);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
std::cerr << "eive-watchdog: Could not created named pipe at " << watchdog::FIFO_NAME
|
std::cerr << "Could not created named pipe at " << watchdog::FIFO_NAME << ", error " << errno
|
||||||
<< ", error " << errno << ": " << strerror(errno) << std::endl;
|
<< ": " << strerror(errno) << std::endl;
|
||||||
throw std::runtime_error("eive-watchdog: FIFO creation failed");
|
throw std::runtime_error("eive-watchdog: FIFO creation failed");
|
||||||
}
|
}
|
||||||
#if WATCHDOG_VERBOSE_LEVEL >= 1
|
#if WATCHDOG_VERBOSE_LEVEL >= 1
|
||||||
std::cout << "eive-watchdog: Pipe at " << watchdog::FIFO_NAME << " created successfully"
|
std::cout << "Pipe at " << watchdog::FIFO_NAME << " created successfully" << std::endl;
|
||||||
<< std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,8 +40,8 @@ int WatchdogTask::performOperation() {
|
|||||||
// Open FIFO read only and non-blocking
|
// Open FIFO read only and non-blocking
|
||||||
fd = open(watchdog::FIFO_NAME.c_str(), O_RDONLY | O_NONBLOCK);
|
fd = open(watchdog::FIFO_NAME.c_str(), O_RDONLY | O_NONBLOCK);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
std::cerr << "eive-watchdog: Opening pipe " << watchdog::FIFO_NAME << "read-only failed with "
|
std::cerr << "Opening pipe " << watchdog::FIFO_NAME << "read-only failed with " << errno << ": "
|
||||||
<< errno << ": " << strerror(errno) << std::endl;
|
<< strerror(errno) << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
state = States::NOT_STARTED;
|
state = States::NOT_STARTED;
|
||||||
@ -54,10 +53,10 @@ int WatchdogTask::performOperation() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (close(fd) < 0) {
|
if (close(fd) < 0) {
|
||||||
std::cerr << "eive-watchdog: Closing named pipe at " << watchdog::FIFO_NAME << "failed, error "
|
std::cerr << "Closing named pipe at " << watchdog::FIFO_NAME << "failed, error " << errno
|
||||||
<< errno << ": " << strerror(errno) << std::endl;
|
<< ": " << strerror(errno) << std::endl;
|
||||||
}
|
}
|
||||||
std::cout << "eive-watchdog: Finished" << std::endl;
|
std::cout << "Closing" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,8 +75,8 @@ WatchdogTask::LoopResult WatchdogTask::watchdogLoop() {
|
|||||||
return pollEvent(waiter);
|
return pollEvent(waiter);
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
std::cerr << "eive-watchdog: Unknown poll error at " << watchdog::FIFO_NAME << ", error "
|
std::cerr << "Unknown poll error at " << watchdog::FIFO_NAME << ", error " << errno << ": "
|
||||||
<< errno << ": " << strerror(errno) << std::endl;
|
<< strerror(errno) << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,8 +87,8 @@ WatchdogTask::LoopResult WatchdogTask::pollEvent(struct pollfd& waiter) {
|
|||||||
if (waiter.revents & POLLIN) {
|
if (waiter.revents & POLLIN) {
|
||||||
ssize_t readLen = read(fd, buf.data(), buf.size());
|
ssize_t readLen = read(fd, buf.data(), buf.size());
|
||||||
if (readLen < 0) {
|
if (readLen < 0) {
|
||||||
std::cerr << "eive-watchdog: Read error on pipe " << watchdog::FIFO_NAME << ", error "
|
std::cerr << "Read error on pipe " << watchdog::FIFO_NAME << ", error " << errno << ": "
|
||||||
<< errno << ": " << strerror(errno) << std::endl;
|
<< strerror(errno) << std::endl;
|
||||||
return LoopResult::OK;
|
return LoopResult::OK;
|
||||||
}
|
}
|
||||||
#if WATCHDOG_VERBOSE_LEVEL == 2
|
#if WATCHDOG_VERBOSE_LEVEL == 2
|
||||||
@ -100,7 +99,7 @@ WatchdogTask::LoopResult WatchdogTask::pollEvent(struct pollfd& waiter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (waiter.revents & POLLERR) {
|
} 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;
|
return LoopResult::FAULT;
|
||||||
} else if (waiter.revents & POLLHUP) {
|
} else if (waiter.revents & POLLHUP) {
|
||||||
// Writer closed its end
|
// Writer closed its end
|
||||||
@ -142,9 +141,9 @@ int WatchdogTask::performRunningOperation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
obswRunning = true;
|
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
|
#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)) {
|
if (not std::filesystem::exists(watchdog::RUNNING_FILE_NAME)) {
|
||||||
std::ofstream obswRunningFile(watchdog::RUNNING_FILE_NAME);
|
std::ofstream obswRunningFile(watchdog::RUNNING_FILE_NAME);
|
||||||
if (not obswRunningFile.good()) {
|
if (not obswRunningFile.good()) {
|
||||||
@ -160,9 +159,9 @@ int WatchdogTask::performNotRunningOperation(LoopResult type) {
|
|||||||
// Latch prevents spam on console
|
// Latch prevents spam on console
|
||||||
if (not printNotRunningLatch) {
|
if (not printNotRunningLatch) {
|
||||||
if (type == LoopResult::HUNG_UP) {
|
if (type == LoopResult::HUNG_UP) {
|
||||||
std::cout << "eive-watchdog: FIFO writer hung up!" << std::endl;
|
std::cout << "OBSW hung up" << std::endl;
|
||||||
} else {
|
} 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;
|
printNotRunningLatch = true;
|
||||||
}
|
}
|
||||||
@ -188,7 +187,7 @@ int WatchdogTask::performNotRunningOperation(LoopResult type) {
|
|||||||
auto timeNotRunning = std::chrono::system_clock::now() - notRunningStart.value();
|
auto timeNotRunning = std::chrono::system_clock::now() - notRunningStart.value();
|
||||||
if (std::chrono::duration_cast<std::chrono::milliseconds>(timeNotRunning).count() >
|
if (std::chrono::duration_cast<std::chrono::milliseconds>(timeNotRunning).count() >
|
||||||
watchdog::MAX_NOT_RUNNING_MS) {
|
watchdog::MAX_NOT_RUNNING_MS) {
|
||||||
std::cout << "Restarting OBSW" << std::endl;
|
std::cout << "Restarting OBSW with systemctl" << std::endl;
|
||||||
std::system("systemctl restart obsw");
|
std::system("systemctl restart obsw");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,7 +216,7 @@ bool WatchdogTask::stateMachine(LoopResult loopResult) {
|
|||||||
}
|
}
|
||||||
case (LoopResult::SUSPEND_REQ): {
|
case (LoopResult::SUSPEND_REQ): {
|
||||||
if (state == States::RUNNING or state == States::FAULTY) {
|
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;
|
state = States::SUSPENDED;
|
||||||
}
|
}
|
||||||
performSuspendOperation();
|
performSuspendOperation();
|
||||||
@ -225,7 +224,7 @@ bool WatchdogTask::stateMachine(LoopResult loopResult) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case (LoopResult::CANCEL_REQ): {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,11 +243,13 @@ bool WatchdogTask::stateMachine(LoopResult loopResult) {
|
|||||||
if (state == States::NOT_STARTED or state == States::FAULTY) {
|
if (state == States::NOT_STARTED or state == States::FAULTY) {
|
||||||
state = States::RUNNING;
|
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) {
|
if (loopResult == LoopResult::START_REQ) {
|
||||||
|
std::cout << "Start request without watch request received" << std::endl;
|
||||||
watchingObsw = false;
|
watchingObsw = false;
|
||||||
} else if (loopResult == LoopResult::START_WITH_WATCH_REQ) {
|
} 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;
|
watchingObsw = true;
|
||||||
}
|
}
|
||||||
performRunningOperation();
|
performRunningOperation();
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* It checks whether the OBSW writes to the the FIFO regularly.
|
* It checks whether the OBSW writes to the the FIFO regularly.
|
||||||
*/
|
*/
|
||||||
int main() {
|
int main() {
|
||||||
std::cout << "eive-watchdog: Starting OBSW watchdog.." << std::endl;
|
std::cout << "Starting OBSW watchdog" << std::endl;
|
||||||
try {
|
try {
|
||||||
WatchdogTask watchdogTask;
|
WatchdogTask watchdogTask;
|
||||||
int result = watchdogTask.performOperation();
|
int result = watchdogTask.performOperation();
|
||||||
@ -15,7 +15,7 @@ int main() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} catch (const std::runtime_error& e) {
|
} 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 -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user