Make dbus-sensors compile with clang-13
clang-13 finds a lot more warnings for unused variables than it used to,
and also picks up some warnings about errant std::moves that are in
place.
This commit fixes them.
Tested:
code compiles against clang-13
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I80864287b7131acfe936c4b28afaf34ababb3029
diff --git a/include/TachSensor.hpp b/include/TachSensor.hpp
index fa9de07..e719293 100644
--- a/include/TachSensor.hpp
+++ b/include/TachSensor.hpp
@@ -28,7 +28,6 @@
private:
bool status = true;
- bool inverted;
gpiod::line gpioLine;
boost::asio::posix::stream_descriptor gpioFd;
std::string name;
diff --git a/src/ADCSensor.cpp b/src/ADCSensor.cpp
index 5abee29..8c335e5 100644
--- a/src/ADCSensor.cpp
+++ b/src/ADCSensor.cpp
@@ -34,7 +34,6 @@
#include <string>
#include <vector>
-static constexpr size_t warnAfterErrorCount = 10;
// scaling factor from hwmon
static constexpr unsigned int sensorScaleFactor = 1000;
diff --git a/src/ADCSensorMain.cpp b/src/ADCSensorMain.cpp
index 4f35a7f..9311834 100644
--- a/src/ADCSensorMain.cpp
+++ b/src/ADCSensorMain.cpp
@@ -35,7 +35,6 @@
#include <variant>
#include <vector>
-static constexpr bool debug = false;
static constexpr float pollRateDefault = 0.5;
static constexpr float gpioBridgeSetupTimeDefault = 0.02;
@@ -75,9 +74,8 @@
{
auto getter = std::make_shared<GetSensorConfiguration>(
dbusConnection,
- std::move([&io, &objectServer, &sensors, &dbusConnection,
- sensorsChanged](
- const ManagedObjectType& sensorConfigurations) {
+ [&io, &objectServer, &sensors, &dbusConnection,
+ sensorsChanged](const ManagedObjectType& sensorConfigurations) {
bool firstScan = sensorsChanged == nullptr;
std::vector<fs::path> paths;
if (!findFiles(fs::path("/sys/class/hwmon"), R"(in\d+_input)",
@@ -306,7 +304,7 @@
readState, *interfacePath, std::move(bridgeGpio));
sensor->setupRead();
}
- }));
+ });
getter->getConfiguration(
std::vector<std::string>{sensorTypes.begin(), sensorTypes.end()});
diff --git a/src/CPUSensorMain.cpp b/src/CPUSensorMain.cpp
index de8607b..73f2ee1 100644
--- a/src/CPUSensorMain.cpp
+++ b/src/CPUSensorMain.cpp
@@ -181,7 +181,6 @@
for (const fs::path& hwmonNamePath : hwmonNamePaths)
{
- const std::string& pathStr = hwmonNamePath.string();
auto hwmonDirectory = hwmonNamePath.parent_path();
auto ret = scannedDirectories.insert(hwmonDirectory.string());
diff --git a/src/ExitAirTempSensor.cpp b/src/ExitAirTempSensor.cpp
index 70b9e7a..0165ffc 100644
--- a/src/ExitAirTempSensor.cpp
+++ b/src/ExitAirTempSensor.cpp
@@ -203,27 +203,26 @@
{
std::weak_ptr<CFMSensor> weakRef = weak_from_this();
- setupSensorMatch(matches, *dbusConnection, "fan_tach",
- std::move([weakRef](const double& value,
- sdbusplus::message::message& message) {
- auto self = weakRef.lock();
- if (!self)
- {
- return;
- }
- self->tachReadings[message.get_path()] = value;
- if (self->tachRanges.find(message.get_path()) ==
- self->tachRanges.end())
- {
- // calls update reading after updating ranges
- self->addTachRanges(message.get_sender(),
- message.get_path());
- }
- else
- {
- self->updateReading();
- }
- }));
+ setupSensorMatch(
+ matches, *dbusConnection, "fan_tach",
+ [weakRef](const double& value, sdbusplus::message::message& message) {
+ auto self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
+ self->tachReadings[message.get_path()] = value;
+ if (self->tachRanges.find(message.get_path()) ==
+ self->tachRanges.end())
+ {
+ // calls update reading after updating ranges
+ self->addTachRanges(message.get_sender(), message.get_path());
+ }
+ else
+ {
+ self->updateReading();
+ }
+ });
dbusConnection->async_method_call(
[weakRef](const boost::system::error_code ec,
@@ -883,9 +882,8 @@
return;
}
auto getter = std::make_shared<GetSensorConfiguration>(
- dbusConnection,
- std::move([&objectServer, &dbusConnection,
- &exitAirSensor](const ManagedObjectType& resp) {
+ dbusConnection, [&objectServer, &dbusConnection,
+ &exitAirSensor](const ManagedObjectType& resp) {
cfmSensors.clear();
for (const auto& pathPair : resp)
{
@@ -955,7 +953,7 @@
exitAirSensor->setupMatches();
exitAirSensor->updateReading();
}
- }));
+ });
getter->getConfiguration(
std::vector<std::string>(monitorIfaces.begin(), monitorIfaces.end()));
}
diff --git a/src/ExternalSensor.cpp b/src/ExternalSensor.cpp
index 17f5300..745c65b 100644
--- a/src/ExternalSensor.cpp
+++ b/src/ExternalSensor.cpp
@@ -95,7 +95,7 @@
// Connect ExternalSensor with Sensor
auto weakThis = weak_from_this();
- externalSetHook = std::move([weakThis]() {
+ externalSetHook = [weakThis]() {
auto lockThis = weakThis.lock();
if (lockThis)
{
@@ -106,7 +106,7 @@
{
std::cerr << "ExternalSensor receive ignored, sensor gone\n";
}
- });
+ };
}
ExternalSensor::~ExternalSensor()
diff --git a/src/ExternalSensorMain.cpp b/src/ExternalSensorMain.cpp
index 647eb5a..1ced726 100644
--- a/src/ExternalSensorMain.cpp
+++ b/src/ExternalSensorMain.cpp
@@ -148,7 +148,7 @@
}
void createSensors(
- boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
+ sdbusplus::asio::object_server& objectServer,
boost::container::flat_map<std::string, std::shared_ptr<ExternalSensor>>&
sensors,
std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
@@ -163,7 +163,7 @@
auto getter = std::make_shared<GetSensorConfiguration>(
dbusConnection,
- [&io, &objectServer, &sensors, &dbusConnection, sensorsChanged,
+ [&objectServer, &sensors, &dbusConnection, sensorsChanged,
&reaperTimer](const ManagedObjectType& sensorConfigurations) {
bool firstScan = (sensorsChanged == nullptr);
@@ -362,15 +362,14 @@
std::make_shared<boost::container::flat_set<std::string>>();
boost::asio::steady_timer reaperTimer(io);
- io.post([&io, &objectServer, &sensors, &systemBus, &reaperTimer]() {
- createSensors(io, objectServer, sensors, systemBus, nullptr,
- reaperTimer);
+ io.post([&objectServer, &sensors, &systemBus, &reaperTimer]() {
+ createSensors(objectServer, sensors, systemBus, nullptr, reaperTimer);
});
boost::asio::deadline_timer filterTimer(io);
std::function<void(sdbusplus::message::message&)> eventHandler =
- [&io, &objectServer, &sensors, &systemBus, &sensorsChanged,
- &filterTimer, &reaperTimer](sdbusplus::message::message& message) {
+ [&objectServer, &sensors, &systemBus, &sensorsChanged, &filterTimer,
+ &reaperTimer](sdbusplus::message::message& message) mutable {
if (message.is_method_error())
{
std::cerr << "callback method error\n";
@@ -388,21 +387,22 @@
// this implicitly cancels the timer
filterTimer.expires_from_now(boost::posix_time::seconds(1));
- filterTimer.async_wait([&io, &objectServer, &sensors, &systemBus,
- &sensorsChanged, &reaperTimer](
- const boost::system::error_code& ec) {
- if (ec != boost::system::errc::success)
- {
- if (ec != boost::asio::error::operation_aborted)
+ filterTimer.async_wait(
+ [&objectServer, &sensors, &systemBus, &sensorsChanged,
+ &reaperTimer](const boost::system::error_code& ec) mutable {
+ if (ec != boost::system::errc::success)
{
- std::cerr << "callback error: " << ec.message() << "\n";
+ if (ec != boost::asio::error::operation_aborted)
+ {
+ std::cerr << "callback error: " << ec.message()
+ << "\n";
+ }
+ return;
}
- return;
- }
- createSensors(io, objectServer, sensors, systemBus,
- sensorsChanged, reaperTimer);
- });
+ createSensors(objectServer, sensors, systemBus,
+ sensorsChanged, reaperTimer);
+ });
};
auto match = std::make_unique<sdbusplus::bus::match::match>(
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index 465ce1b..cb0afd3 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -39,8 +39,6 @@
#include <variant>
#include <vector>
-static constexpr bool debug = false;
-
namespace fs = std::filesystem;
// The following two structures need to be consistent
@@ -163,9 +161,8 @@
{
auto getter = std::make_shared<GetSensorConfiguration>(
dbusConnection,
- std::move([&io, &objectServer, &tachSensors, &pwmSensors,
- &dbusConnection, sensorsChanged](
- const ManagedObjectType& sensorConfigurations) {
+ [&io, &objectServer, &tachSensors, &pwmSensors, &dbusConnection,
+ sensorsChanged](const ManagedObjectType& sensorConfigurations) {
bool firstScan = sensorsChanged == nullptr;
std::vector<fs::path> paths;
if (!findFiles(fs::path("/sys/class/hwmon"), R"(fan\d+_input)",
@@ -448,7 +445,7 @@
}
createRedundancySensor(tachSensors, dbusConnection, objectServer);
- }));
+ });
getter->getConfiguration(
std::vector<std::string>{sensorTypes.begin(), sensorTypes.end()},
retries);
diff --git a/src/HwmonTempMain.cpp b/src/HwmonTempMain.cpp
index 4f259dc..d9fe52d 100644
--- a/src/HwmonTempMain.cpp
+++ b/src/HwmonTempMain.cpp
@@ -36,7 +36,6 @@
#include <variant>
#include <vector>
-static constexpr bool debug = false;
static constexpr float pollRateDefault = 0.5;
namespace fs = std::filesystem;
@@ -69,9 +68,8 @@
{
auto getter = std::make_shared<GetSensorConfiguration>(
dbusConnection,
- std::move([&io, &objectServer, &sensors, &dbusConnection,
- sensorsChanged](
- const ManagedObjectType& sensorConfigurations) {
+ [&io, &objectServer, &sensors, &dbusConnection,
+ sensorsChanged](const ManagedObjectType& sensorConfigurations) {
bool firstScan = sensorsChanged == nullptr;
std::vector<fs::path> paths;
@@ -89,7 +87,6 @@
for (auto& path : paths)
{
std::smatch match;
- const std::string& pathStr = path.string();
auto directory = path.parent_path();
auto ret = directories.insert(directory.string());
@@ -296,7 +293,7 @@
}
}
}
- }));
+ });
getter->getConfiguration(
std::vector<std::string>(sensorTypes.begin(), sensorTypes.end()));
}
diff --git a/src/IntrusionSensorMain.cpp b/src/IntrusionSensorMain.cpp
index 154b2b2..ad4794a 100644
--- a/src/IntrusionSensorMain.cpp
+++ b/src/IntrusionSensorMain.cpp
@@ -183,8 +183,7 @@
const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
{
auto getter = std::make_shared<GetSensorConfiguration>(
- dbusConnection,
- std::move([](const ManagedObjectType& sensorConfigurations) {
+ dbusConnection, [](const ManagedObjectType& sensorConfigurations) {
// Get NIC name and save to map
lanInfoMap.clear();
for (const std::pair<sdbusplus::message::object_path, SensorData>&
@@ -228,7 +227,7 @@
{
std::cerr << "can't find matched NIC name. \n";
}
- }));
+ });
getter->getConfiguration(
std::vector<std::string>{nicTypes.begin(), nicTypes.end()});
diff --git a/src/TachSensor.cpp b/src/TachSensor.cpp
index 7242c96..d2afba7 100644
--- a/src/TachSensor.cpp
+++ b/src/TachSensor.cpp
@@ -38,7 +38,6 @@
#include <vector>
static constexpr unsigned int pwmPollMs = 500;
-static constexpr size_t warnAfterErrorCount = 10;
TachSensor::TachSensor(const std::string& path, const std::string& objectType,
sdbusplus::asio::object_server& objectServer,
@@ -204,8 +203,8 @@
PresenceSensor::PresenceSensor(const std::string& gpioName, bool inverted,
boost::asio::io_service& io,
const std::string& name) :
- inverted(inverted),
- gpioLine(gpiod::find_line(gpioName)), gpioFd(io), name(name)
+ gpioLine(gpiod::find_line(gpioName)),
+ gpioFd(io), name(name)
{
if (!gpioLine)
{
diff --git a/src/Thresholds.cpp b/src/Thresholds.cpp
index bbe8e20..c52eee6 100644
--- a/src/Thresholds.cpp
+++ b/src/Thresholds.cpp
@@ -344,13 +344,13 @@
}
}
- if constexpr (debug)
+ // Throttle debug output, so that it does not continuously spam
+ ++cDebugThrottle;
+ if (cDebugThrottle >= 1000)
{
- // Throttle debug output, so that it does not continuously spam
- ++cDebugThrottle;
- if (cDebugThrottle >= 1000)
+ cDebugThrottle = 0;
+ if constexpr (debug)
{
- cDebugThrottle = 0;
std::cerr << "checkThresholds: High T=" << cHiTrue
<< " F=" << cHiFalse << " M=" << cHiMidstate
<< ", Low T=" << cLoTrue << " F=" << cLoFalse