diff options
author | Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com> | 2022-01-26 18:51:08 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-26 18:51:08 +0300 |
commit | 8542fa62c13306e8e8cc623183f105a868a36b6c (patch) | |
tree | 34c1706af99fe436a247d2ac49e6fb0faa8f29c2 | |
parent | 6165e07cd0ef6da314ed1ef4f58fe47b7d8112db (diff) | |
download | virtual-media-8542fa62c13306e8e8cc623183f105a868a36b6c.tar.xz |
Add -Wextra, remove warnings (#1)
Removed all -Wextra warnings in VM sources.
-Wno-unused-parameter has to be disabled due to lots of such warnings in
sdbusplus.
Tested:
Compilation generates no warnings
Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/events.hpp | 4 | ||||
-rw-r--r-- | src/state/activating_state.cpp | 19 | ||||
-rw-r--r-- | src/state/active_state.hpp | 8 | ||||
-rw-r--r-- | src/state/initial_state.hpp | 37 | ||||
-rw-r--r-- | src/state/ready_state.hpp | 10 | ||||
-rw-r--r-- | src/state_machine.hpp | 2 |
7 files changed, 52 insertions, 32 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e9eb2a4..97778d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,9 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-rtti") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fno-rtti") +# Silence sdbusplus warnings +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os -flto") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") diff --git a/src/events.hpp b/src/events.hpp index 7a6adde..320d344 100644 --- a/src/events.hpp +++ b/src/events.hpp @@ -22,14 +22,12 @@ struct RegisterDbusEvent : public BasicEvent std::shared_ptr<sdbusplus::asio::connection> bus, std::shared_ptr<sdbusplus::asio::object_server> objServer) : BasicEvent(__FUNCTION__), - bus(bus), objServer(objServer), - emitMountEvent(std::move(emitMountEvent)) + bus(bus), objServer(objServer) { } std::shared_ptr<sdbusplus::asio::connection> bus; std::shared_ptr<sdbusplus::asio::object_server> objServer; - std::function<void(void)> emitMountEvent; }; struct MountEvent : public BasicEvent diff --git a/src/state/activating_state.cpp b/src/state/activating_state.cpp index 7506aed..686de99 100644 --- a/src/state/activating_state.cpp +++ b/src/state/activating_state.cpp @@ -48,8 +48,8 @@ std::unique_ptr<BasicState> std::move(gadget), event); } -std::unique_ptr<BasicState> - ActivatingState::handleEvent(SubprocessStoppedEvent event) +std::unique_ptr<BasicState> ActivatingState::handleEvent([ + [maybe_unused]] SubprocessStoppedEvent event) { LogMsg(Logger::Error, "Process ended prematurely"); return std::make_unique<ReadyState>(machine); @@ -229,7 +229,7 @@ std::unique_ptr<resource::Process> args.insert(args.end(), params.begin(), params.end()); if (!process->spawn(args, [&machine = machine, secret = std::move(secret)]( - int exitCode, bool isReady) { + int exitCode, [[maybe_unused]] bool isReady) { LogMsg(Logger::Info, machine.getName(), " process ended."); machine.getExitCode() = exitCode; machine.emitSubprocessStoppedEvent(); @@ -278,11 +278,12 @@ std::unique_ptr<resource::Process> { // Pack password into buffer utils::CredentialsProvider::SecureBuffer buff = - machine.getTarget()->credentials->pack([](const std::string& user, - const std::string& pass, - std::vector<char>& buff) { - std::copy(pass.begin(), pass.end(), std::back_inserter(buff)); - }); + machine.getTarget()->credentials->pack( + []([[maybe_unused]] const std::string& user, + const std::string& pass, std::vector<char>& buff) { + std::copy(pass.begin(), pass.end(), + std::back_inserter(buff)); + }); // Prepare file to provide the password with secret = std::make_unique<utils::VolatileFile>(std::move(buff)); @@ -319,7 +320,7 @@ bool ActivatingState::getImagePathFromUrl(const std::string& urlScheme, } else { - LogMsg(Logger::Error, "Provied url does not match scheme"); + LogMsg(Logger::Error, "Provided url does not match scheme"); return false; } } diff --git a/src/state/active_state.hpp b/src/state/active_state.hpp index a2a8653..a204dc3 100644 --- a/src/state/active_state.hpp +++ b/src/state/active_state.hpp @@ -45,7 +45,8 @@ struct ActiveState : public BasicStateT<ActiveState> // unmount media & stop retriggering timer boost::asio::spawn( machine.getIoc(), - [&machine = machine](boost::asio::yield_context yield) { + [&machine = machine]( + [[maybe_unused]] boost::asio::yield_context yield) { machine.emitUnmountEvent(); }); return; @@ -77,7 +78,7 @@ struct ActiveState : public BasicStateT<ActiveState> machine, std::move(process), std::move(gadget), std::move(event)); } - std::unique_ptr<BasicState> handleEvent(UnmountEvent event) + std::unique_ptr<BasicState> handleEvent([[maybe_unused]] UnmountEvent event) { return std::make_unique<DeactivatingState>(machine, std::move(process), std::move(gadget)); @@ -86,7 +87,8 @@ struct ActiveState : public BasicStateT<ActiveState> [[noreturn]] std::unique_ptr<BasicState> handleEvent(MountEvent event) { LogMsg(Logger::Error, "InvalidĀ event: ", event.eventName); - throw sdbusplus::exception::SdBusError(EPERM, "Operation not permitted in active state"); + throw sdbusplus::exception::SdBusError( + EPERM, "Operation not permitted in active state"); } template <class AnyEvent> diff --git a/src/state/initial_state.hpp b/src/state/initial_state.hpp index 02fe479..0529d9f 100644 --- a/src/state/initial_state.hpp +++ b/src/state/initial_state.hpp @@ -2,6 +2,8 @@ #include "basic_state.hpp" #include "ready_state.hpp" +#include <system_error> + struct InitialState : public BasicStateT<InitialState> { static std::string_view stateName() @@ -70,14 +72,15 @@ struct InitialState : public BasicStateT<InitialState> processIface->register_property( "Active", bool(false), - [](const bool& req, bool& property) { return 0; }, - [&machine = machine](const bool& property) -> bool { - return machine.getState().get_if<ActiveState>(); - }); + []([[maybe_unused]] const bool& req, + [[maybe_unused]] bool& property) { return 0; }, + [&machine = machine]([[maybe_unused]] const bool& property) + -> bool { return machine.getState().get_if<ActiveState>(); }); processIface->register_property( "ExitCode", int32_t(0), - [](const int32_t& req, int32_t& property) { return 0; }, - [&machine = machine](const int32_t& property) { + []([[maybe_unused]] const int32_t& req, + [[maybe_unused]] int32_t& property) { return 0; }, + [&machine = machine]([[maybe_unused]] const int32_t& property) { return machine.getExitCode(); }); processIface->initialize(); @@ -137,12 +140,14 @@ struct InitialState : public BasicStateT<InitialState> iface->register_property("Socket", machine.getConfig().unixSocket); iface->register_property( "ImageURL", std::string(), - [](const std::string& req, std::string& property) { + []([[maybe_unused]] const std::string& req, + [[maybe_unused]] std::string& property) { throw sdbusplus::exception::SdBusError( EPERM, "Setting ImageURL property is not allowed"); return -1; }, - [&target = machine.getTarget()](const std::string& property) { + [&target = machine.getTarget()]( + [[maybe_unused]] const std::string& property) { if (target) { return target->imgUrl; @@ -151,8 +156,10 @@ struct InitialState : public BasicStateT<InitialState> }); iface->register_property( "WriteProtected", bool(true), - [](const bool& req, bool& property) { return 0; }, - [&target = machine.getTarget()](const bool& property) { + []([[maybe_unused]] const bool& req, + [[maybe_unused]] bool& property) { return 0; }, + [&target = + machine.getTarget()]([[maybe_unused]] const bool& property) { if (target) { return !target->rw; @@ -164,13 +171,15 @@ struct InitialState : public BasicStateT<InitialState> Configuration::MountPoint::defaultTimeout)); iface->register_property( "RemainingInactivityTimeout", 0, - [](const int& req, int& property) { + []([[maybe_unused]] const int& req, + [[maybe_unused]] int& property) { throw sdbusplus::exception::SdBusError( EPERM, "Setting RemainingInactivityTimeout property is " "not allowed"); return -1; }, - [&config = machine.getConfig()](const int& property) -> int { + [&config = machine.getConfig()]( + [[maybe_unused]] const int& property) -> int { return config.remainingInactivityTimeout.count(); }); iface->initialize(); @@ -280,8 +289,8 @@ struct InitialState : public BasicStateT<InitialState> LogMsg(Logger::Info, "[App]: Mount called on ", getObjectPath(machine), machine.getName()); - interfaces::MountPointStateMachine::Target target = {imgUrl, - rw}; + interfaces::MountPointStateMachine::Target target = { + imgUrl, rw, nullptr, nullptr}; if (std::holds_alternative<unix_fd>(fd)) { diff --git a/src/state/ready_state.hpp b/src/state/ready_state.hpp index 2243143..bf1e160 100644 --- a/src/state/ready_state.hpp +++ b/src/state/ready_state.hpp @@ -2,6 +2,13 @@ #include "activating_state.hpp" #include "basic_state.hpp" +#include "logger.hpp" + +#include <chrono> +#include <memory> +#include <optional> +#include <string> +#include <system_error> struct ReadyState : public BasicStateT<ReadyState> { @@ -50,7 +57,8 @@ struct ReadyState : public BasicStateT<ReadyState> [[noreturn]] std::unique_ptr<BasicState> handleEvent(UnmountEvent event) { LogMsg(Logger::Error, "InvalidĀ event: ", event.eventName); - throw sdbusplus::exception::SdBusError(EPERM, "Operation not permitted in ready state"); + throw sdbusplus::exception::SdBusError( + EPERM, "Operation not permitted in ready state"); } template <class AnyEvent> diff --git a/src/state_machine.hpp b/src/state_machine.hpp index 3e525cf..259802c 100644 --- a/src/state_machine.hpp +++ b/src/state_machine.hpp @@ -53,7 +53,7 @@ struct MountPointStateMachine : public interfaces::MountPointStateMachine { state = std::move(newState); LogMsg(Logger::Info, name, " state changed to ", state->getStateName()); - if (newState = state->onEnter()) + if ((newState = state->onEnter())) { changeState(std::move(newState)); } |