Enable cppcoreguidelines-avoid-goto checks

We've been pretty good about this one, the only usages seem to be in
nvme sensor and added recently.  To move to more RAII compliant
containers, this commit creates a FileHandle class, which accepts either
a file path and a mode, or a direct file handle, to be handled via RAII.
Ideally we wouldn't have to create this ourselves, and could rely on
some library, but the alternatives all have compromises that are worse.

boost::asio::random_access_file requires iouring to be enabled, and
isn't available until boost 0.78, which we haven't rebased to yet.
https://www.boost.org/doc/libs/develop/doc/html/boost_asio/reference/random_access_file.html
Once available, this is what I would hope that a bunch of the nvme stuff
evolves into to be much simpler.

boost::iostream::file_descriptor requires linking against
boost::iostream, which would bloat our binary size for a lot of things
we don't use.  There is a file_descriptor.cpp that we could compile
directly to solve this, but the existing yocto boost project (nor any
other distro project) installs these files for use, which would
complicate this solution

std::fstream doesn't allow direct access to the file handle, which would
be required for streaming operations.

https://www.boost.org/doc/libs/1_35_0/libs/iostreams/doc/installation.html
https://www.boost.org/doc/libs/1_78_0/libs/iostreams/doc/classes/file_descriptor.html#file_descriptor

A very similar class exists within ipmid here:
https://github.com/openbmc/phosphor-host-ipmid/blob/master/user_channel/file.hpp

This class differs in a couple minor ways, in that it throws exceptions
on open failures (similar to the boost classes), accepts the input by
std::filesystem::path, instead of string, and supports std::move, which
is required for the pipe usage.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I8be2419783e41e8f529030bb3d05c2e7aa890307
5 files changed
tree: c0cc1e25977e015ea04b798bdc45420590d61483
  1. include/
  2. service_files/
  3. src/
  4. subprojects/
  5. tests/
  6. .clang-format
  7. .clang-ignore
  8. .clang-tidy
  9. .gitignore
  10. Jenkinsfile
  11. LICENSE
  12. MAINTAINERS
  13. meson.build
  14. meson_options.txt
  15. OWNERS
  16. README.md
README.md

dbus-sensors

dbus-sensors is a collection of sensor applications that provide the xyz.openbmc_project.Sensor collection of interfaces. They read sensor values from hwmon, d-bus, or direct driver access to provide readings. Some advance non-sensor features such as fan presence, pwm control, and automatic cpu detection (x86) are also supported.

key features

  • runtime re-configurable from d-bus (entity-manager or the like)

  • isolated: each sensor type is isolated into its own daemon, so a bug in one sensor is unlikely to affect another, and single sensor modifications are possible

  • async single-threaded: uses sdbusplus/asio bindings

  • multiple data inputs: hwmon, d-bus, direct driver access

sensor documentation