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.
This commit is contained in:
Julian Brost 2021-06-21 16:07:36 +02:00
parent 23aa628665
commit 36ce7d961f
4 changed files with 18 additions and 9 deletions

View File

@ -276,7 +276,7 @@ int RunWorker(const std::vector<std::string>& 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;
}

View File

@ -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<ConfigItem::Ptr>& newItems, bool runtimeCreated,
bool silent, bool withModAttrs, const Value& cookie)
bool mainConfigActivation, bool withModAttrs, const Value& cookie)
{
static std::mutex mtx;
std::unique_lock<std::mutex> lock(mtx);
@ -663,7 +673,7 @@ bool ConfigItem::ActivateItems(const std::vector<ConfigItem::Ptr>& 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<ConfigItem::Ptr>& 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;

View File

@ -54,7 +54,7 @@ public:
static bool CommitItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector<ConfigItem::Ptr>& newItems, bool silent = false);
static bool ActivateItems(const std::vector<ConfigItem::Ptr>& 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);

View File

@ -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 << "'.";