From 5c7eaabb3ee5e247f5198feb49c0a1efc8e6cd29 Mon Sep 17 00:00:00 2001 From: Maciej Kaszynski Date: Tue, 5 May 2026 14:13:46 +0100 Subject: [PATCH] Using std::string_view for logging --- .../lcm/internal/controlclientchannel.hpp | 3 +- .../src/internal/controlclientchannel.cpp | 4 +- .../score/lcm/saf/factory/FlatCfgFactory.cpp | 16 +++---- .../lcm/saf/factory/MachineConfigFactory.cpp | 5 +- .../src/score/lcm/saf/ifappl/Checkpoint.cpp | 4 +- .../src/score/lcm/saf/ifappl/Checkpoint.hpp | 3 +- .../src/score/lcm/saf/supervision/Alive.cpp | 8 ++-- .../lcm/saf/supervision/ISupervision.cpp | 4 +- .../lcm/saf/supervision/ISupervision.hpp | 6 +-- .../src/score/lcm/saf/supervision/Local.cpp | 7 +-- .../src/score/lcm/saf/supervision/Local.hpp | 5 +- .../configurationmanager.cpp | 10 ++-- .../src/process_group_manager/graph.cpp | 2 +- .../src/process_group_manager/graph.hpp | 3 +- .../process_group_manager/processinfonode.cpp | 4 +- .../process_group_manager/processlauncher.cpp | 48 ++++++++++--------- 16 files changed, 70 insertions(+), 62 deletions(-) diff --git a/src/launch_manager_daemon/common/include/score/lcm/internal/controlclientchannel.hpp b/src/launch_manager_daemon/common/include/score/lcm/internal/controlclientchannel.hpp index f3014402..fb58c5a9 100644 --- a/src/launch_manager_daemon/common/include/score/lcm/internal/controlclientchannel.hpp +++ b/src/launch_manager_daemon/common/include/score/lcm/internal/controlclientchannel.hpp @@ -16,6 +16,7 @@ #define CONTROL_CLIENT_CHANNEL_HPP_INCLUDED #include +#include #include #include #include @@ -247,7 +248,7 @@ class ControlClientChannel final { /// @brief A utility function that converts codes to strings for logging purposes /// @param code The code to convert /// @return A string representing the code - const char* toString(ControlClientCode code); + std::string_view toString(ControlClientCode code); private: diff --git a/src/launch_manager_daemon/common/src/internal/controlclientchannel.cpp b/src/launch_manager_daemon/common/src/internal/controlclientchannel.cpp index 3536aa81..c37cb6cd 100644 --- a/src/launch_manager_daemon/common/src/internal/controlclientchannel.cpp +++ b/src/launch_manager_daemon/common/src/internal/controlclientchannel.cpp @@ -134,7 +134,7 @@ ControlClientChannelP ControlClientChannel::initializeControlClientChannel(int f if (MAP_FAILED == channelMemory) { - LM_LOG_ERROR() << "mmap failed in initializeControlClientChannel:" << std::strerror(errno); + LM_LOG_ERROR() << "mmap failed in initializeControlClientChannel:" << std::string_view{std::strerror(errno)}; return nullptr; } @@ -239,7 +239,7 @@ void ControlClientChannel::releaseParentMapping() ipc_parent_.reset(); } -const char* ControlClientChannel::toString(ControlClientCode code) +std::string_view ControlClientChannel::toString(ControlClientCode code) { for (const auto& mapping : stateArray) { diff --git a/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/factory/FlatCfgFactory.cpp b/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/factory/FlatCfgFactory.cpp index 625bca85..509407af 100644 --- a/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/factory/FlatCfgFactory.cpp +++ b/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/factory/FlatCfgFactory.cpp @@ -185,7 +185,7 @@ bool FlatCfgFactory::createProcessStates(std::vector& f_pro { isSuccess = false; logger_r.LogError() << kLogPrefix - << "Could not create Process States due to exception:" << f_exception_r.what(); + << "Could not create Process States due to exception:" << std::string_view{f_exception_r.what()}; } } else @@ -272,7 +272,7 @@ bool FlatCfgFactory::createMonitorIfIpcs(std::vector& f_int f_interfaces_r.clear(); logger_r.LogError() << kLogPrefix << "Could not create all necessary Monitor interfaces due to exception:" - << f_exception_r.what(); + << std::string_view{f_exception_r.what()}; } return isSuccess; @@ -375,7 +375,7 @@ bool FlatCfgFactory::createSupervisionCheckpoints(std::vector& f_ logger_r.LogError() << kLogPrefix << "Could not create all necessary alive supervision " "worker objects, due to exception:" - << f_exception_r.what(); + << std::string_view{f_exception_r.what()}; } } @@ -541,7 +541,7 @@ bool FlatCfgFactory::createLocalSupervisions(std::vector& f_ { isSuccess = false; logger_r.LogError() << kLogPrefix << "Could not create local supervision worker objects, due to exception:" - << f_exception_r.what(); + << std::string_view{f_exception_r.what()}; } } else @@ -649,7 +649,7 @@ bool FlatCfgFactory::createGlobalSupervisions(std::vector& { isGlobalSupCfgSuccess = false; logger_r.LogError() << kLogPrefix << "Could not create all necessary global supervision due to exception:" - << f_exception_r.what(); + << std::string_view{f_exception_r.what()}; } } else @@ -702,7 +702,7 @@ bool FlatCfgFactory::createRecoveryNotifications(std::shared_ptr +#include #include #include "score/lcm/saf/timers/TimeConversion.hpp" #include "hmcore_flatcfg_generated.h" @@ -191,8 +192,8 @@ void MachineConfigFactory::logConfiguration() noexcept(true) std::uint32_t wdgCount{1U}; for (const auto& wdgConfig : watchdogConfigs) { - const char* const wdgMagicCloseBool{wdgConfig.needsMagicClose ? "true" : "false"}; - const char* const wdgDeactivatedBool{wdgConfig.canBeDeactivated ? "true" : "false"}; + const std::string_view wdgMagicCloseBool{wdgConfig.needsMagicClose ? "true" : "false"}; + const std::string_view wdgDeactivatedBool{wdgConfig.canBeDeactivated ? "true" : "false"}; logger_r.LogDebug() << kLogPrefix << "Watchdog" << wdgCount << "- device file:" << wdgConfig.fileName; logger_r.LogDebug() << kLogPrefix << "Watchdog" << wdgCount << "- max timeout:" << wdgConfig.timeoutMax << "ms"; logger_r.LogDebug() << kLogPrefix << "Watchdog" << wdgCount << "- needs magic close:" << wdgMagicCloseBool; diff --git a/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/ifappl/Checkpoint.cpp b/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/ifappl/Checkpoint.cpp index 333e7539..e4fce4b7 100644 --- a/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/ifappl/Checkpoint.cpp +++ b/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/ifappl/Checkpoint.cpp @@ -67,9 +67,9 @@ bool Checkpoint::getDataLossEvent(void) const noexcept(true) return isDataLossEvent; } -const char* Checkpoint::getConfigName(void) const noexcept(true) +std::string_view Checkpoint::getConfigName(void) const noexcept(true) { - return k_configName.c_str(); + return k_configName; } const ifexm::ProcessState* Checkpoint::getProcess(void) const noexcept(true) diff --git a/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/ifappl/Checkpoint.hpp b/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/ifappl/Checkpoint.hpp index 69c61793..5e2f91e5 100644 --- a/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/ifappl/Checkpoint.hpp +++ b/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/ifappl/Checkpoint.hpp @@ -15,6 +15,7 @@ #define CHECKPOINT_HPP_INCLUDED #include +#include #include @@ -93,7 +94,7 @@ class Checkpoint : public saf::common::Observable /// @brief Get the configuration name of the corresponding SupervisionCheckpoint /// @return Name of the corresponding SupervisionCheckpoint (configuration element) - const char* getConfigName(void) const noexcept(true); + std::string_view getConfigName(void) const noexcept(true); /// @brief Return the process that is reporting this checkpoint /// @return process state diff --git a/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/Alive.cpp b/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/Alive.cpp index be6013a9..b454807b 100644 --- a/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/Alive.cpp +++ b/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/Alive.cpp @@ -14,6 +14,7 @@ #include "score/lcm/saf/supervision/Alive.hpp" #include +#include #include "score/lcm/saf/common/Types.hpp" #include "score/lcm/saf/ifexm/ProcessState.hpp" @@ -546,7 +547,7 @@ bool Alive::isMaxError(void) const noexcept(true) void Alive::logExpiredFailedStateDetails() const noexcept(true) { - const char* failedState{""}; + std::string_view failedState{""}; if (aliveStatus == Alive::EStatus::failed) { // failedSupervisionCycles == 1 if just switched to FAILED and > 1 if were already in FAILED before @@ -559,11 +560,10 @@ void Alive::logExpiredFailedStateDetails() const noexcept(true) const bool minError{isMinError()}; /* RULECHECKER_comment(0, 4, check_conditional_as_sub_expression, "Ternary operation is very simple", true_no_defect) */ - const char* indication{((indicationCount != 1U) ? "indications" : "indication")}; const std::uint64_t aliveIndicationMargin{minError ? k_minAliveIndications : k_maxAliveIndications}; - const char* expectedComparison{minError ? ">=" : "<="}; + const std::string_view expectedComparison{minError ? ">=" : "<="}; logger_r.LogWarn() << "Alive Supervision (" << getConfigName() << ")" << failedState << ", due to" - << indicationCount << "reported alive" << indication << "(expected" << expectedComparison + << indicationCount << "reported alive indication(s) (expected" << expectedComparison << aliveIndicationMargin << "). Failed supervision cycles:" << failedSupervisionCycles << "/" << k_failedSupervisionCyclesTolerance; } diff --git a/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/ISupervision.cpp b/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/ISupervision.cpp index aa3db3f3..071aaa7e 100644 --- a/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/ISupervision.cpp +++ b/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/ISupervision.cpp @@ -28,9 +28,9 @@ ISupervision::ISupervision(const char* const f_supervisionConfigName_p) : k_cfgN static_cast(0); } -const char* ISupervision::getConfigName(void) const +std::string_view ISupervision::getConfigName(void) const noexcept { - return static_cast(k_cfgName.c_str()); + return k_cfgName; } } // namespace supervision diff --git a/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/ISupervision.hpp b/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/ISupervision.hpp index 3faea5b2..97b354db 100644 --- a/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/ISupervision.hpp +++ b/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/ISupervision.hpp @@ -17,6 +17,7 @@ #include #include +#include #include #include "score/lcm/saf/timers/Timers_OsClock.hpp" @@ -56,9 +57,8 @@ class ISupervision virtual void evaluate(const timers::NanoSecondType f_syncTimestamp) = 0; /// @brief Get the name of the configuration element for the corresponding supervision container - /// @return std::string Constant string containing the name of the - /// corresponding supervision configuration container - const char* getConfigName(void) const; + /// @return std::string_view View over the name of the corresponding supervision configuration container + std::string_view getConfigName(void) const noexcept; protected: /// @brief Default Move Constructor diff --git a/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/Local.cpp b/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/Local.cpp index 1467ff27..999c8804 100644 --- a/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/Local.cpp +++ b/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/Local.cpp @@ -14,6 +14,7 @@ #include "score/lcm/saf/supervision/Local.hpp" #include +#include #include "score/lcm/saf/logging/PhmLogger.hpp" #include "score/lcm/saf/timers/Timers_OsClock.hpp" @@ -282,7 +283,7 @@ void Local::switchToOk(ICheckpointSupervision::EType f_type) noexcept pushResultToObservers(); } -void Local::switchToFailed(ICheckpointSupervision::EType f_type, const char* reason_p) noexcept +void Local::switchToFailed(ICheckpointSupervision::EType f_type, std::string_view reason_p) noexcept { supervisionType = f_type; logger_r.LogWarn() << "Local Supervision (" << getConfigName() << ") switched to FAILED," << reason_p; @@ -291,11 +292,11 @@ void Local::switchToFailed(ICheckpointSupervision::EType f_type, const char* rea } void Local::switchToExpired(ICheckpointSupervision::EType f_type, - ifexm::ProcessCfg::ProcessExecutionError f_executionError, const char* reason_p) noexcept + ifexm::ProcessCfg::ProcessExecutionError f_executionError, std::string_view reason_p) noexcept { supervisionType = f_type; processExecutionError = f_executionError; - if (nullptr == reason_p) + if (reason_p.empty()) { if (ICheckpointSupervision::EType::aliveSupervision == f_type) { diff --git a/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/Local.hpp b/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/Local.hpp index dde175ec..6ee3bc7f 100644 --- a/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/Local.hpp +++ b/src/launch_manager_daemon/health_monitor_lib/src/score/lcm/saf/supervision/Local.hpp @@ -19,6 +19,7 @@ #endif #include +#include #include @@ -174,7 +175,7 @@ class Local : public ISupervision, /// @brief Switch to state Failed /// @param [in] f_type Type of Supervision /// @param [in] reason_p Reason for switch to Failed - void switchToFailed(const ICheckpointSupervision::EType f_type, const char* reason_p) noexcept; + void switchToFailed(const ICheckpointSupervision::EType f_type, std::string_view reason_p) noexcept; /// @brief Switch to state Expired /// @details In case reason_p was given f_type will be ignored. @@ -183,7 +184,7 @@ class Local : public ISupervision, /// @param [in] reason_p [Optional] Other reason for switch to Expired void switchToExpired(ICheckpointSupervision::EType f_type, ifexm::ProcessCfg::ProcessExecutionError f_executionError, - const char* reason_p = nullptr) noexcept; + std::string_view reason_p = {}) noexcept; /// @brief Check if ALL attached Supervisions are in status Deactivated bool isAllDeactivated() const noexcept; diff --git a/src/launch_manager_daemon/src/configuration_manager/configurationmanager.cpp b/src/launch_manager_daemon/src/configuration_manager/configurationmanager.cpp index cacc770a..bdd1b39c 100644 --- a/src/launch_manager_daemon/src/configuration_manager/configurationmanager.cpp +++ b/src/launch_manager_daemon/src/configuration_manager/configurationmanager.cpp @@ -303,7 +303,7 @@ bool ConfigurationManager::parseMachineConfigurations(const ModeGroup* node, con ProcessGroup process_group_data; process_group_data.name_ = getStringViewFromFlatBuffer(node->identifier()); process_group_data.sw_cluster_ = cluster; - LM_LOG_DEBUG() << "FlatBufferParser::getModeGroupPgName:" << getStringFromFlatBuffer(node->identifier()) + LM_LOG_DEBUG() << "FlatBufferParser::getModeGroupPgName:" << std::string_view{getStringFromFlatBuffer(node->identifier())} << "( IdentifierHash:" << process_group_data.name_.data() << ")"; if (process_group_data.name_ != score::lcm::IdentifierHash(std::string_view(""))) { @@ -338,7 +338,7 @@ bool ConfigurationManager::parseModeGroups(const ModeGroup* node, ProcessGroup& std::string string_name(flatbuffer_string->c_str(), flatbuffer_string->size()); pg_state.name_ = getStringViewFromFlatBuffer(flatbuffer_string); LM_LOG_DEBUG() << "FlatBufferParser::getModeGroupPgStateName:" - << mode_declaration_node->identifier()->c_str() + << std::string_view{flatbuffer_string->c_str(), flatbuffer_string->size()} << "( IdentifierHash:" << pg_state.name_.data() << ")"; process_group_data.states_.push_back(pg_state); // Is this the "Off" state, i.e. does it end with "/Off" ? @@ -395,7 +395,7 @@ static void setSchedulingParameters(const Process& node, const ProcessStartupCon } else if (strcasecmp("SCHED_OTHER", attribute->c_str()) == 0) { instance.startup_config_.scheduling_policy_ = SCHED_OTHER; } else { - LM_LOG_WARN() << "scheduling policy" << attribute->c_str() << "is not supported, using default"; + LM_LOG_WARN() << "scheduling policy" << std::string_view{attribute->c_str(), attribute->size()} << "is not supported, using default"; } } attribute = config.schedulingPriority(); @@ -617,7 +617,7 @@ void ConfigurationManager::parseExecutionDependency( dep.process_state_ = getProcessState(state_name); dep.target_process_id_ = getStringViewFromFlatBuffer(process_dependency_node->targetProcess_identifier()); LM_LOG_DEBUG() << "ParseProcessExecutionDependency: target process path:" - << getStringFromFlatBuffer(process_dependency_node->targetProcess_identifier()) + << std::string_view{getStringFromFlatBuffer(process_dependency_node->targetProcess_identifier())} << "ID:" << dep.target_process_id_; process_instance.dependencies_.push_back(dep); @@ -761,7 +761,7 @@ bool ConfigurationManager::checkOrSetFlatConfigEnvVar(const std::string& name, c const char* value = getenv(name.c_str()); if (value && strlen(value)) { - LM_LOG_DEBUG() << name.c_str() << "already set. Current value:" << value; + LM_LOG_DEBUG() << name << "already set. Current value:" << std::string_view{value}; result = true; } else { if (setenv(name.c_str(), path.c_str(), overwrite_) == 0) { diff --git a/src/launch_manager_daemon/src/process_group_manager/graph.cpp b/src/launch_manager_daemon/src/process_group_manager/graph.cpp index 5866c0b5..46c8e2c4 100644 --- a/src/launch_manager_daemon/src/process_group_manager/graph.cpp +++ b/src/launch_manager_daemon/src/process_group_manager/graph.cpp @@ -468,7 +468,7 @@ ControlClientMessage& Graph::getCancelMessage() { return cancel_message_; } -const char* Graph::toString(GraphState state) { +std::string_view Graph::toString(GraphState state) { switch (state) { case GraphState::kAborting: return "kAborting"; diff --git a/src/launch_manager_daemon/src/process_group_manager/graph.hpp b/src/launch_manager_daemon/src/process_group_manager/graph.hpp index 398ada28..ce320e87 100644 --- a/src/launch_manager_daemon/src/process_group_manager/graph.hpp +++ b/src/launch_manager_daemon/src/process_group_manager/graph.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -302,7 +303,7 @@ class Graph final { /// @brief A utility function that converts codes to strings for logging purposes /// @param state The state to convert /// @return A string representing the state - static const char* toString(GraphState state); + static std::string_view toString(GraphState state); /// @brief Sets the state transition request start time void setRequestStartTime(); diff --git a/src/launch_manager_daemon/src/process_group_manager/processinfonode.cpp b/src/launch_manager_daemon/src/process_group_manager/processinfonode.cpp index 57f2adb0..bf07eac9 100644 --- a/src/launch_manager_daemon/src/process_group_manager/processinfonode.cpp +++ b/src/launch_manager_daemon/src/process_group_manager/processinfonode.cpp @@ -246,7 +246,7 @@ void ProcessInfoNode::startProcess() { if (osal::CommsType::kLaunchManager == config_->startup_config_.comms_type_) { // Don't start launch manager, we're already running - LM_LOG_DEBUG() << "Found myself (" << config_->startup_config_.argv_[0U] + LM_LOG_DEBUG() << "Found myself (" << std::string_view{config_->startup_config_.argv_[0U]} << ") in a process group to start, not starting, reporting kRunning"; pid_ = getpid(); static_cast(setState(score::lcm::ProcessState::kRunning)); // Cannot fail by design @@ -393,7 +393,7 @@ void ProcessInfoNode::terminateProcess() { if (setState(score::lcm::ProcessState::kTerminating)) { if (osal::CommsType::kLaunchManager == config_->startup_config_.comms_type_) { - LM_LOG_DEBUG() << "Found myself (" << config_->startup_config_.argv_[0U] + LM_LOG_DEBUG() << "Found myself (" << std::string_view{config_->startup_config_.argv_[0U]} << ") in a process group to terminate, not terminating, reporting kTerminated"; static_cast(setState(score::lcm::ProcessState::kTerminated)); // Cannot fail by design } else { diff --git a/src/launch_manager_daemon/src/process_group_manager/processlauncher.cpp b/src/launch_manager_daemon/src/process_group_manager/processlauncher.cpp index c505e9b6..b98c8d0a 100644 --- a/src/launch_manager_daemon/src/process_group_manager/processlauncher.cpp +++ b/src/launch_manager_daemon/src/process_group_manager/processlauncher.cpp @@ -11,6 +11,8 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ +#include + #include #include #include @@ -67,7 +69,7 @@ void handleComms(score::lcm::internal::osal::ChildProcessConfig& param) case CommsType::kReporting: if (-1 == fcntl(IpcCommsSync::sync_fd, F_SETFD, 0)) { - LM_LOG_ERROR() << "[New process] fcntl() at line" << __LINE__ << "failed:" << std::strerror(errno); + LM_LOG_ERROR() << "[New process] fcntl() at line" << __LINE__ << "failed:" << std::string_view{std::strerror(errno)}; sysexit(EXIT_FAILURE); } close(IpcCommsSync::control_client_handler_nudge_fd); @@ -75,12 +77,12 @@ void handleComms(score::lcm::internal::osal::ChildProcessConfig& param) case CommsType::kControlClient: if (-1 == fcntl(IpcCommsSync::sync_fd, F_SETFD, 0)) { - LM_LOG_ERROR() << "[New process] fcntl() at line" << __LINE__ << "failed:" << std::strerror(errno); + LM_LOG_ERROR() << "[New process] fcntl() at line" << __LINE__ << "failed:" << std::string_view{std::strerror(errno)}; sysexit(EXIT_FAILURE); } if (-1 == fcntl(IpcCommsSync::control_client_handler_nudge_fd, F_SETFD, 0)) { - LM_LOG_ERROR() << "[New process] fcntl() at line" << __LINE__ << "failed:" << std::strerror(errno); + LM_LOG_ERROR() << "[New process] fcntl() at line" << __LINE__ << "failed:" << std::string_view{std::strerror(errno)}; } break; case CommsType::kLaunchManager: @@ -102,13 +104,13 @@ void handleComms(score::lcm::internal::osal::ChildProcessConfig& param) if (-1 == param.fd) { - LM_LOG_ERROR() << "[New process] shm_open() failed:" << std::strerror(errno); + LM_LOG_ERROR() << "[New process] shm_open() failed:" << std::string_view{std::strerror(errno)}; sysexit(EXIT_FAILURE); } if (-1 == shm_unlink(shmem_name)) { - LM_LOG_ERROR() << "[New process] shm_unlink() failed:" << std::strerror(errno); + LM_LOG_ERROR() << "[New process] shm_unlink() failed:" << std::string_view{std::strerror(errno)}; sysexit(EXIT_FAILURE); } } @@ -131,7 +133,7 @@ void changeCurrentWorkingDirectory(const score::lcm::internal::osal::OsalConfig& if (-1 == chdir(dirname(strncpy(path_copy, config.executable_path_.c_str(), string_size)))) { - LM_LOG_ERROR() << "[New process] chdir(" << config.executable_path_ << ") failed:" << std::strerror(errno); + LM_LOG_ERROR() << "[New process] chdir(" << config.executable_path_ << ") failed:" << std::string_view{std::strerror(errno)}; sysexit(EXIT_FAILURE); } } @@ -146,7 +148,7 @@ void implementMemoryResourceLimits(const score::lcm::internal::osal::OsalConfig& if (setrlimit(RLIMIT_DATA, &limit) == -1) { LM_LOG_ERROR() << "[New process] setrlimit(RLIMIT_DATA," << limit.rlim_cur - << ") failed:" << std::strerror(errno); + << ") failed:" << std::string_view{std::strerror(errno)}; sysexit(EXIT_FAILURE); } } @@ -157,7 +159,7 @@ void implementMemoryResourceLimits(const score::lcm::internal::osal::OsalConfig& if (setrlimit(RLIMIT_AS, &limit) == -1) { LM_LOG_ERROR() << "[New process] setrlimit(RLIMIT_AS," << limit.rlim_cur - << "failed:" << std::strerror(errno); + << "failed:" << std::string_view{std::strerror(errno)}; sysexit(EXIT_FAILURE); } } @@ -168,7 +170,7 @@ void implementMemoryResourceLimits(const score::lcm::internal::osal::OsalConfig& if (setrlimit(RLIMIT_STACK, &limit) == -1) { LM_LOG_ERROR() << "[New process] setrlimit(RLIMIT_STACK," << limit.rlim_cur - << ") failed:" << std::strerror(errno); + << ") failed:" << std::string_view{std::strerror(errno)}; sysexit(EXIT_FAILURE); } } @@ -183,7 +185,7 @@ void implementMemoryResourceLimits(const score::lcm::internal::osal::OsalConfig& if (setrlimit(RLIMIT_CPU, &limit) == -1) { LM_LOG_ERROR() << "[New process] setrlimit(RLIMIT_CPU," << limit.rlim_cur - << ") failed:" << std::strerror(errno); + << ") failed:" << std::string_view{std::strerror(errno)}; sysexit(EXIT_FAILURE); } } @@ -196,7 +198,7 @@ void changeSecurityPolicy(const score::lcm::internal::osal::OsalConfig& config) if (score::lcm::internal::osal::setSecurityPolicy(config.security_policy_.c_str()) != 0) { LM_LOG_ERROR() << "[New process] changeSecurityPolicy(" << config.security_policy_ - << ") failed:" << strerror(errno); + << ") failed:" << std::string_view{strerror(errno)}; sysexit(EXIT_FAILURE); } } @@ -303,7 +305,7 @@ inline bool IProcess::setupComms(IpcCommsP& block, int& fd, const OsalConfig& co if (fd < 0) { LM_LOG_ERROR() << "shm_open failed:" << config.executable_path_ - << "Unable to open shared memory object. Error:" << std::strerror(errno); + << "Unable to open shared memory object. Error:" << std::string_view{std::strerror(errno)}; comms_result = false; } else @@ -314,7 +316,7 @@ inline bool IProcess::setupComms(IpcCommsP& block, int& fd, const OsalConfig& co { comms_result = false; LM_LOG_ERROR() << "ftruncate failed:" << config.executable_path_ - << "Unable to set size of shared memory file descriptor. Error:" << std::strerror(errno); + << "Unable to set size of shared memory file descriptor. Error:" << std::string_view{std::strerror(errno)}; } if (config.comms_type_ == CommsType::kControlClient) @@ -382,7 +384,7 @@ OsalReturnType IProcess::setSchedulingAndSecurity(const OsalConfig& config) // setpgid will fail if called by a session lader (which LCMd is), so skip if (config.comms_type_ != osal::CommsType::kLaunchManager && 0 != setpgid(0, getpid())) { - LM_LOG_ERROR() << "setpgid() failed:" << std::strerror(errno); + LM_LOG_ERROR() << "setpgid() failed:" << std::string_view{std::strerror(errno)}; retval = OsalReturnType::kFail; } // Set scheduling policy with sched_setscheduler @@ -406,21 +408,21 @@ OsalReturnType IProcess::setSchedulingAndSecurity(const OsalConfig& config) if (-1 == sched_setscheduler(0, config.scheduling_policy_, &sch_param)) { - LM_LOG_ERROR() << "sched_setscheduler() failed:" << std::strerror(errno); + LM_LOG_ERROR() << "sched_setscheduler() failed:" << std::string_view{std::strerror(errno)}; retval = OsalReturnType::kFail; } // Set core affinity using OS specific functionality in osal if (-1 == osal::setaffinity(config.cpu_mask_)) { - LM_LOG_ERROR() << "setaffinity(" << config.cpu_mask_ << ") failed:" << std::strerror(errno); + LM_LOG_ERROR() << "setaffinity(" << config.cpu_mask_ << ") failed:" << std::string_view{std::strerror(errno)}; retval = OsalReturnType::kFail; } // Set group ID if (-1 == setgid(config.gid_)) { - LM_LOG_ERROR() << "setgid(" << config.gid_ << ") failed:" << std::strerror(errno); + LM_LOG_ERROR() << "setgid(" << config.gid_ << ") failed:" << std::string_view{std::strerror(errno)}; retval = OsalReturnType::kFail; } // Set supplementary group ids @@ -430,14 +432,14 @@ OsalReturnType IProcess::setSchedulingAndSecurity(const OsalConfig& config) if (supplementary_gids_number > 0 && -1 == osal::setgroups(supplementary_gids_number, config.supplementary_gids_.data())) { - LM_LOG_ERROR() << "setgroups() failed:" << std::strerror(errno); + LM_LOG_ERROR() << "setgroups() failed:" << std::string_view{std::strerror(errno)}; retval = OsalReturnType::kFail; } // Set user ID if (-1 == setuid(config.uid_)) { - LM_LOG_ERROR() << "setuid(" << config.uid_ << ") failed:" << std::strerror(errno); + LM_LOG_ERROR() << "setuid(" << config.uid_ << ") failed:" << std::string_view{std::strerror(errno)}; retval = OsalReturnType::kFail; } @@ -464,7 +466,7 @@ inline void IProcess::handleChildProcess(ChildProcessConfig& param) if (-1 == execve(param.config->argv_[0], const_cast(param.config->argv_.data()), param.config->envp_)) { LM_LOG_ERROR() << "[New process] execve failed: Unable to execute the" << param.config->executable_path_ - << "app. Error:" << std::strerror(errno); + << "app. Error:" << std::string_view{std::strerror(errno)}; sysexit(EXIT_FAILURE); } } @@ -484,7 +486,7 @@ OsalReturnType IProcess::requestTermination(ProcessID pid) else { LM_LOG_ERROR() << "SIGTERM failed: Unable to send SIGTERM to process ID" << pid - << ". Error:" << std::strerror(errno); + << ". Error:" << std::string_view{std::strerror(errno)}; } } else @@ -541,7 +543,7 @@ OsalReturnType IProcess::waitForTermination(osal::ProcessID& pid, int32_t& statu { /// exiting with pid == 0 is perfectly normal behaviour when all process groups are in the Off state. LM_LOG_DEBUG() << "wait failed: Unable to wait for any child process to terminate. Error:" - << std::strerror(errno); + << std::string_view{std::strerror(errno)}; } return result; @@ -583,7 +585,7 @@ OsalReturnType IProcess::waitForkRunning(IpcCommsP sync, std::chrono::millisecon else { LM_LOG_WARN() << "Skipping semaphore deinitialization - shared memory region appears invalid: " - << std::strerror(errno); + << std::string_view{std::strerror(errno)}; } } else