From 1022a247992c6437bec8903c0139d8b1dd9eca33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20=C3=96hrstr=C3=B6m?= Date: Fri, 25 Sep 2020 17:02:42 +0200 Subject: [PATCH] Non-working implies opened first. --- src/main.cc | 4 ++-- src/serial.cc | 9 +++++---- src/wmbus.cc | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main.cc b/src/main.cc index ec773f1..4139d62 100644 --- a/src/main.cc +++ b/src/main.cc @@ -525,7 +525,7 @@ void check_for_dead_wmbus_devices(Configuration *config) not_working.push_back(w.get()); if (config->use_auto_detect) { - info("Lost %s closing %s\n", w->device().c_str(), toString(w->type())); + notice("Lost %s closing %s\n", w->device().c_str(), toString(w->type())); } } } @@ -863,7 +863,7 @@ bool start(Configuration *config) if (!meter_manager_->hasMeters()) { - notice("No meters configured. Printing id:s of all telegrams heard!\n\n"); + notice("No meters configured. Printing id:s of all telegrams heard!\n"); meter_manager_->onTelegram([](vector frame) { Telegram t; diff --git a/src/serial.cc b/src/serial.cc index de821e3..1ed3fb0 100644 --- a/src/serial.cc +++ b/src/serial.cc @@ -464,6 +464,7 @@ AccessCheck SerialDeviceCommand::open(bool fail_if_not_ok) { expectAscii(); bool ok = invokeBackgroundShell("/bin/sh", args_, envs_, &fd_, &pid_); + assert(fd_ >= 0); if (!ok) return AccessCheck::NotThere; setIsStdin(); verbose("(serialcmd) opened %s pid %d fd %d\n", command_.c_str(), pid_, fd_); @@ -790,7 +791,7 @@ void SerialCommunicationManagerImp::removeNonWorkingSerialDevices() for (auto i = serial_devices_.begin(); i != serial_devices_.end(); ) { - if (!(*i)->working()) + if ((*i)->opened() && !(*i)->working()) { i = serial_devices_.erase(i); } @@ -927,7 +928,7 @@ void *SerialCommunicationManagerImp::eventLoop() trace("(SERIAL) select read on fd %d\n", sd->fd()); FD_SET(sd->fd(), &readfds); } - if (!sd->working()) all_working = false; + if (sd->opened() && !sd->working()) all_working = false; } } @@ -995,13 +996,13 @@ void *SerialCommunicationManagerImp::eventLoop() for (shared_ptr &sd : serial_devices_) { - if (!sd->working()) non_working.push_back(sd); + if (sd->opened() && !sd->working()) non_working.push_back(sd); } } for (shared_ptr &sd : non_working) { - debug("(serial) closing non working fd=%d\n", sd->fd()); + debug("(serial) closing non working fd=%d \"%s\"\n", sd->fd(), sd->device().c_str()); sd->close(); } diff --git a/src/wmbus.cc b/src/wmbus.cc index 5c1e057..5a93cd5 100644 --- a/src/wmbus.cc +++ b/src/wmbus.cc @@ -3383,7 +3383,7 @@ void WMBusCommonImplementation::disconnectedFromDevice() { if (is_working_) { - debug("(wmbus) disconnect %s closing %s\n", device().c_str(), toString(type())); + debug("(wmbus) disconnected %s %s\n", device().c_str(), toString(type())); is_working_ = false; } }