diff options
-rw-r--r-- | .clang-tidy | 1 | ||||
-rw-r--r-- | http/http_connection.hpp | 1 | ||||
-rw-r--r-- | include/dbus_monitor.hpp | 8 | ||||
-rw-r--r-- | include/dbus_singleton.hpp | 1 | ||||
-rw-r--r-- | include/forward_unauthorized.hpp | 1 | ||||
-rw-r--r-- | include/hostname_monitor.hpp | 1 | ||||
-rw-r--r-- | include/image_upload.hpp | 1 | ||||
-rw-r--r-- | include/kvm_websocket.hpp | 7 | ||||
-rw-r--r-- | include/nbd_proxy.hpp | 9 | ||||
-rw-r--r-- | include/obmc_console.hpp | 5 | ||||
-rw-r--r-- | include/vm_websocket.hpp | 2 | ||||
-rw-r--r-- | include/webroutes.hpp | 1 | ||||
-rw-r--r-- | redfish-core/include/event_service_manager.hpp | 5 | ||||
-rw-r--r-- | redfish-core/lib/certificate_service.hpp | 1 | ||||
-rw-r--r-- | redfish-core/lib/sensors.hpp | 28 | ||||
-rw-r--r-- | redfish-core/lib/task.hpp | 1 | ||||
-rw-r--r-- | redfish-core/lib/update_service.hpp | 4 | ||||
-rw-r--r-- | src/dbus_singleton.cpp | 2 |
18 files changed, 55 insertions, 24 deletions
diff --git a/.clang-tidy b/.clang-tidy index 7d9979fafe..bad6111fcb 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -202,6 +202,7 @@ clang-analyzer-webkit.NoUncountedMemberChecker, clang-analyzer-webkit.RefCntblBaseVirtualDtor, cppcoreguidelines-avoid-c-arrays, cppcoreguidelines-avoid-goto, +cppcoreguidelines-avoid-non-const-global-variables, cppcoreguidelines-c-copy-assignment-signature, cppcoreguidelines-explicit-virtual-functions, cppcoreguidelines-init-variables, diff --git a/http/http_connection.hpp b/http/http_connection.hpp index 1c1bfd9885..45581fdf26 100644 --- a/http/http_connection.hpp +++ b/http/http_connection.hpp @@ -41,6 +41,7 @@ inline void prettyPrintJson(crow::Response& res) "text/html;charset=UTF-8"); } +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static int connectionCount = 0; // request body limit size set by the bmcwebHttpReqBodyLimitMb option diff --git a/include/dbus_monitor.hpp b/include/dbus_monitor.hpp index 0838f0ae6c..3bad07002d 100644 --- a/include/dbus_monitor.hpp +++ b/include/dbus_monitor.hpp @@ -24,9 +24,11 @@ struct DbusWebsocketSession interfaces; }; -static boost::container::flat_map<crow::websocket::Connection*, - DbusWebsocketSession> - sessions; +using SessionMap = boost::container::flat_map<crow::websocket::Connection*, + DbusWebsocketSession>; + +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) +static SessionMap sessions; inline int onPropertyUpdate(sd_bus_message* m, void* userdata, sd_bus_error* retError) diff --git a/include/dbus_singleton.hpp b/include/dbus_singleton.hpp index 283021641b..f9b50b078d 100644 --- a/include/dbus_singleton.hpp +++ b/include/dbus_singleton.hpp @@ -9,6 +9,7 @@ namespace connections // Initialze before using! // Please see webserver_main for the example how this variable is initialzed, +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) extern sdbusplus::asio::connection* systemBus; } // namespace connections diff --git a/include/forward_unauthorized.hpp b/include/forward_unauthorized.hpp index 2fc3ee45f5..850a0b79b0 100644 --- a/include/forward_unauthorized.hpp +++ b/include/forward_unauthorized.hpp @@ -6,6 +6,7 @@ namespace forward_unauthorized { +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static bool hasWebuiRoute = false; inline void sendUnauthorized(std::string_view url, diff --git a/include/hostname_monitor.hpp b/include/hostname_monitor.hpp index 3fb42e49c0..cb84ad67d0 100644 --- a/include/hostname_monitor.hpp +++ b/include/hostname_monitor.hpp @@ -11,6 +11,7 @@ namespace crow { namespace hostname_monitor { +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static std::unique_ptr<sdbusplus::bus::match_t> hostnameSignalMonitor; inline void installCertificate(const std::filesystem::path& certPath) diff --git a/include/image_upload.hpp b/include/image_upload.hpp index 4defbb6682..bdb7b951ac 100644 --- a/include/image_upload.hpp +++ b/include/image_upload.hpp @@ -16,6 +16,7 @@ namespace crow namespace image_upload { +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static std::unique_ptr<sdbusplus::bus::match_t> fwUpdateMatcher; inline void diff --git a/include/kvm_websocket.hpp b/include/kvm_websocket.hpp index 79975d2c01..1a067ac0fc 100644 --- a/include/kvm_websocket.hpp +++ b/include/kvm_websocket.hpp @@ -150,9 +150,10 @@ class KvmSession bool doingWrite{false}; }; -static boost::container::flat_map<crow::websocket::Connection*, - std::unique_ptr<KvmSession>> - sessions; +using SessionMap = boost::container::flat_map<crow::websocket::Connection*, + std::unique_ptr<KvmSession>>; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) +static SessionMap sessions; inline void requestRoutes(App& app) { diff --git a/include/nbd_proxy.hpp b/include/nbd_proxy.hpp index ac3a8113c1..68491cb86b 100644 --- a/include/nbd_proxy.hpp +++ b/include/nbd_proxy.hpp @@ -34,7 +34,7 @@ namespace nbd_proxy using boost::asio::local::stream_protocol; static constexpr auto nbdBufferSize = 131088; -static const char* requiredPrivilegeString = "ConfigureManager"; +constexpr const char* requiredPrivilegeString = "ConfigureManager"; struct NbdProxyServer : std::enable_shared_from_this<NbdProxyServer> { @@ -247,9 +247,10 @@ struct NbdProxyServer : std::enable_shared_from_this<NbdProxyServer> crow::websocket::Connection& connection; }; -static boost::container::flat_map<crow::websocket::Connection*, - std::shared_ptr<NbdProxyServer>> - sessions; +using SessionMap = boost::container::flat_map<crow::websocket::Connection*, + std::shared_ptr<NbdProxyServer>>; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) +static SessionMap sessions; inline void requestRoutes(App& app) { diff --git a/include/obmc_console.hpp b/include/obmc_console.hpp index d5eaf819e7..b8f69435fc 100644 --- a/include/obmc_console.hpp +++ b/include/obmc_console.hpp @@ -12,13 +12,18 @@ namespace crow namespace obmc_console { +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static std::unique_ptr<boost::asio::local::stream_protocol::socket> hostSocket; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static std::array<char, 4096> outputBuffer; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static std::string inputBuffer; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static boost::container::flat_set<crow::websocket::Connection*> sessions; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static bool doingWrite = false; inline void doWrite() diff --git a/include/vm_websocket.hpp b/include/vm_websocket.hpp index ebf0a698e1..1d3bf96c4c 100644 --- a/include/vm_websocket.hpp +++ b/include/vm_websocket.hpp @@ -14,6 +14,7 @@ namespace crow namespace obmc_vm { +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static crow::websocket::Connection* session = nullptr; // The max network block device buffer size is 128kb plus 16bytes @@ -157,6 +158,7 @@ class Handler : public std::enable_shared_from_this<Handler> inputBuffer; }; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static std::shared_ptr<Handler> handler; inline void requestRoutes(App& app) diff --git a/include/webroutes.hpp b/include/webroutes.hpp index 757a272d23..ec1bb23959 100644 --- a/include/webroutes.hpp +++ b/include/webroutes.hpp @@ -6,6 +6,7 @@ namespace crow namespace webroutes { +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static boost::container::flat_set<std::string> routes; } // namespace webroutes diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp index 6f1e91b2d9..d2a4a74348 100644 --- a/redfish-core/include/event_service_manager.hpp +++ b/redfish-core/include/event_service_manager.hpp @@ -77,12 +77,17 @@ inline std::span<const MessageEntry> } // namespace registries #ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static std::optional<boost::asio::posix::stream_descriptor> inotifyConn; static constexpr const char* redfishEventLogDir = "/var/log"; static constexpr const char* redfishEventLogFile = "/var/log/redfish"; static constexpr const size_t iEventSize = sizeof(inotify_event); + +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static int inotifyFd = -1; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static int dirWatchDesc = -1; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static int fileWatchDesc = -1; // <ID, timestamp, RedfishLogId, registryPrefix, MessageId, MessageArgs> diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp index a65f33cd0a..f5633793b1 100644 --- a/redfish-core/lib/certificate_service.hpp +++ b/redfish-core/lib/certificate_service.hpp @@ -569,6 +569,7 @@ inline void handleReplaceCertificateAction( certFile->getCertFilePath()); } +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static std::unique_ptr<sdbusplus::bus::match_t> csrMatcher; /** * @brief Read data from CSR D-bus object and set to response diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp index 00b2ba61f6..f5c4c3ba1a 100644 --- a/redfish-core/lib/sensors.hpp +++ b/redfish-core/lib/sensors.hpp @@ -59,12 +59,12 @@ static constexpr std::string_view thermal = "Thermal"; // clang-format off namespace dbus { -static auto powerPaths = std::to_array<std::string_view>({ +constexpr auto powerPaths = std::to_array<std::string_view>({ "/xyz/openbmc_project/sensors/voltage", "/xyz/openbmc_project/sensors/power" }); -static auto sensorPaths = std::to_array<std::string_view>({ +constexpr auto sensorPaths = std::to_array<std::string_view>({ "/xyz/openbmc_project/sensors/power", "/xyz/openbmc_project/sensors/current", "/xyz/openbmc_project/sensors/airflow", @@ -80,7 +80,7 @@ static auto sensorPaths = std::to_array<std::string_view>({ "/xyz/openbmc_project/sensors/utilization" }); -static auto thermalPaths = std::to_array<std::string_view>({ +constexpr auto thermalPaths = std::to_array<std::string_view>({ "/xyz/openbmc_project/sensors/fan_tach", "/xyz/openbmc_project/sensors/temperature", "/xyz/openbmc_project/sensors/fan_pwm" @@ -89,11 +89,12 @@ static auto thermalPaths = std::to_array<std::string_view>({ } // namespace dbus // clang-format on -using sensorPair = std::pair<std::string_view, std::span<std::string_view>>; +using sensorPair = + std::pair<std::string_view, std::span<const std::string_view>>; static constexpr std::array<sensorPair, 3> paths = { - {{node::power, std::span<std::string_view>(dbus::powerPaths)}, - {node::sensors, std::span<std::string_view>(dbus::sensorPaths)}, - {node::thermal, std::span<std::string_view>(dbus::thermalPaths)}}}; + {{node::power, dbus::powerPaths}, + {node::sensors, dbus::sensorPaths}, + {node::thermal, dbus::thermalPaths}}}; inline sensor::ReadingType toReadingType(std::string_view sensorType) { @@ -203,7 +204,7 @@ class SensorsAsyncResp SensorsAsyncResp(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn, const std::string& chassisIdIn, - std::span<std::string_view> typesIn, + std::span<const std::string_view> typesIn, std::string_view subNode) : asyncResp(asyncRespIn), chassisId(chassisIdIn), types(typesIn), chassisSubNode(subNode), @@ -213,7 +214,7 @@ class SensorsAsyncResp // Store extra data about sensor mapping and return it in callback SensorsAsyncResp(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn, const std::string& chassisIdIn, - std::span<std::string_view> typesIn, + std::span<const std::string_view> typesIn, std::string_view subNode, DataCompleteCb&& creationComplete) : asyncResp(asyncRespIn), @@ -225,7 +226,7 @@ class SensorsAsyncResp // sensor collections expand SensorsAsyncResp(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn, const std::string& chassisIdIn, - const std::span<std::string_view> typesIn, + std::span<const std::string_view> typesIn, const std::string_view& subNode, bool efficientExpandIn) : asyncResp(asyncRespIn), chassisId(chassisIdIn), types(typesIn), chassisSubNode(subNode), @@ -288,7 +289,7 @@ class SensorsAsyncResp const std::shared_ptr<bmcweb::AsyncResp> asyncResp; const std::string chassisId; - const std::span<std::string_view> types; + const std::span<const std::string_view> types; const std::string chassisSubNode; const bool efficientExpand; @@ -443,7 +444,7 @@ void getConnections(std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp, */ inline void reduceSensorList( crow::Response& res, std::string_view chassisSubNode, - std::span<std::string_view> sensorTypes, + std::span<const std::string_view> sensorTypes, const std::vector<std::string>* allSensors, const std::shared_ptr<std::set<std::string>>& activeSensors) { @@ -515,7 +516,8 @@ inline void populateChassisNode(nlohmann::json& jsonValue, template <typename Callback> void getChassis(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string_view chassisId, std::string_view chassisSubNode, - std::span<std::string_view> sensorTypes, Callback&& callback) + std::span<const std::string_view> sensorTypes, + Callback&& callback) { BMCWEB_LOG_DEBUG << "getChassis enter"; constexpr std::array<std::string_view, 2> interfaces = { diff --git a/redfish-core/lib/task.hpp b/redfish-core/lib/task.hpp index fe3b9908bb..6b0096c8ce 100644 --- a/redfish-core/lib/task.hpp +++ b/redfish-core/lib/task.hpp @@ -33,6 +33,7 @@ namespace task { constexpr size_t maxTaskCount = 100; // arbitrary limit +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static std::deque<std::shared_ptr<struct TaskData>> tasks; constexpr bool completed = true; diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp index faf8948c0c..fe6024b699 100644 --- a/redfish-core/lib/update_service.hpp +++ b/redfish-core/lib/update_service.hpp @@ -30,11 +30,15 @@ namespace redfish { // Match signals added on software path +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static std::unique_ptr<sdbusplus::bus::match_t> fwUpdateMatcher; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static std::unique_ptr<sdbusplus::bus::match_t> fwUpdateErrorMatcher; // Only allow one update at a time +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static bool fwUpdateInProgress = false; // Timer for software available +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) static std::unique_ptr<boost::asio::steady_timer> fwAvailableTimer; inline static void cleanUp() diff --git a/src/dbus_singleton.cpp b/src/dbus_singleton.cpp index f78164fbe2..726c3d4bb5 100644 --- a/src/dbus_singleton.cpp +++ b/src/dbus_singleton.cpp @@ -6,7 +6,7 @@ namespace crow { namespace connections { - +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) sdbusplus::asio::connection* systemBus = nullptr; } // namespace connections |