From 36ce7d961f18dd5273cbb38b6ca7b1ecec644eeb Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Mon, 21 Jun 2021 16:07:36 +0200 Subject: [PATCH] Rename silent parameter of ConfigItem::ActivateItems() As silent now no longer only controls the generation of log messages, a better name is required. This changes its name, inverts its value to reflect the new name and adds a documentation comment. --- lib/cli/daemoncommand.cpp | 2 +- lib/config/configitem.cpp | 21 +++++++++++++++------ lib/config/configitem.hpp | 2 +- lib/remote/configobjectutility.cpp | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/cli/daemoncommand.cpp b/lib/cli/daemoncommand.cpp index e25048c1b..30ce74f6c 100644 --- a/lib/cli/daemoncommand.cpp +++ b/lib/cli/daemoncommand.cpp @@ -276,7 +276,7 @@ int RunWorker(const std::vector& configs, bool closeConsoleLog = fa } // activate config only after daemonization: it starts threads and that is not compatible with fork() - if (!ConfigItem::ActivateItems(newItems, false, false, true)) { + if (!ConfigItem::ActivateItems(newItems, false, true, true)) { Log(LogCritical, "cli", "Error activating configuration."); return EXIT_FAILURE; } diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index cb241eb8c..8e6ab0e91 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -624,8 +624,18 @@ bool ConfigItem::CommitItems(const ActivationContext::Ptr& context, WorkQueue& u return true; } +/** + * ActivateItems activates new config items. + * + * @param newItems Vector of items to be activated + * @param runtimeCreated Whether the objects were created by a runtime object + * @param mainConfigActivation Whether this is the call for activating the main configuration during startup + * @param withModAttrs Whether this call shall read the modified attributes file + * @param cookie Cookie for preventing message loops + * @return Whether the config activation was successful (in case of errors, exceptions are thrown) + */ bool ConfigItem::ActivateItems(const std::vector& newItems, bool runtimeCreated, - bool silent, bool withModAttrs, const Value& cookie) + bool mainConfigActivation, bool withModAttrs, const Value& cookie) { static std::mutex mtx; std::unique_lock lock(mtx); @@ -663,7 +673,7 @@ bool ConfigItem::ActivateItems(const std::vector& newItems, boo object->PreActivate(); } - if (!silent) + if (mainConfigActivation) Log(LogInformation, "ConfigItem", "Triggering Start signal for config items"); /* Activate objects in priority order. */ @@ -704,14 +714,13 @@ bool ConfigItem::ActivateItems(const std::vector& newItems, boo object->Activate(runtimeCreated, cookie); } - // TODO: find a better name for silent - if (!silent && type == lastLoggerType) { + if (mainConfigActivation && type == lastLoggerType) { /* Disable early logging configuration once the last logger type was activated. */ Logger::DisableEarlyLogging(); } } - if (!silent) + if (mainConfigActivation) Log(LogInformation, "ConfigItem", "Activated all objects."); return true; @@ -734,7 +743,7 @@ bool ConfigItem::RunWithActivationContext(const Function::Ptr& function) if (!CommitItems(scope.GetContext(), upq, newItems, true)) return false; - if (!ActivateItems(newItems, false, true)) + if (!ActivateItems(newItems, false, false)) return false; return true; diff --git a/lib/config/configitem.hpp b/lib/config/configitem.hpp index b3e4ca35d..b99cd08e5 100644 --- a/lib/config/configitem.hpp +++ b/lib/config/configitem.hpp @@ -54,7 +54,7 @@ public: static bool CommitItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector& newItems, bool silent = false); static bool ActivateItems(const std::vector& newItems, bool runtimeCreated = false, - bool silent = false, bool withModAttrs = false, const Value& cookie = Empty); + bool mainConfigActivation = false, bool withModAttrs = false, const Value& cookie = Empty); static bool RunWithActivationContext(const Function::Ptr& function); diff --git a/lib/remote/configobjectutility.cpp b/lib/remote/configobjectutility.cpp index 6ba0e0ecc..e086ca3fb 100644 --- a/lib/remote/configobjectutility.cpp +++ b/lib/remote/configobjectutility.cpp @@ -224,7 +224,7 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full * uq, items, runtimeCreated, silent, withModAttrs, cookie * IMPORTANT: Forward the cookie aka origin in order to prevent sync loops in the same zone! */ - if (!ConfigItem::ActivateItems(newItems, true, true, false, cookie)) { + if (!ConfigItem::ActivateItems(newItems, true, false, false, cookie)) { if (errors) { Log(LogNotice, "ConfigObjectUtility") << "Failed to activate config object '" << fullName << "'. Aborting and removing config path '" << path << "'.";