Merge branch 'collectd-5.7'
[collectd.git] / src / daemon / configfile.c
index d5f01e0..654cc49 100644 (file)
@@ -245,7 +245,7 @@ static int dispatch_value_plugindir(oconfig_item_t *ci) {
 
 static int dispatch_loadplugin(oconfig_item_t *ci) {
   const char *name;
-  unsigned int flags = 0;
+  _Bool global = 0;
   plugin_ctx_t ctx = {0};
   plugin_ctx_t old_ctx;
   int ret_val;
@@ -270,7 +270,7 @@ static int dispatch_loadplugin(oconfig_item_t *ci) {
     oconfig_item_t *child = ci->children + i;
 
     if (strcasecmp("Globals", child->key) == 0)
-      cf_util_get_flag(child, &flags, PLUGIN_FLAGS_GLOBAL);
+      cf_util_get_boolean(child, &global);
     else if (strcasecmp("Interval", child->key) == 0)
       cf_util_get_cdtime(child, &ctx.interval);
     else if (strcasecmp("FlushInterval", child->key) == 0)
@@ -285,7 +285,7 @@ static int dispatch_loadplugin(oconfig_item_t *ci) {
   }
 
   old_ctx = plugin_set_ctx(ctx);
-  ret_val = plugin_load(name, (uint32_t)flags);
+  ret_val = plugin_load(name, global);
   /* reset to the "global" context */
   plugin_set_ctx(old_ctx);
 
@@ -1119,14 +1119,36 @@ int cf_util_get_boolean(const oconfig_item_t *ci, _Bool *ret_bool) /* {{{ */
   if ((ci == NULL) || (ret_bool == NULL))
     return (EINVAL);
 
-  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
+  if ((ci->values_num != 1) || ((ci->values[0].type != OCONFIG_TYPE_BOOLEAN) &&
+                                (ci->values[0].type != OCONFIG_TYPE_STRING))) {
     ERROR("cf_util_get_boolean: The %s option requires "
           "exactly one boolean argument.",
           ci->key);
     return (-1);
   }
 
-  *ret_bool = ci->values[0].value.boolean ? 1 : 0;
+  switch (ci->values[0].type) {
+  case OCONFIG_TYPE_BOOLEAN:
+    *ret_bool = ci->values[0].value.boolean ? 1 : 0;
+    break;
+  case OCONFIG_TYPE_STRING:
+    WARNING("cf_util_get_boolean: Using string value `%s' for boolean option "
+            "`%s' is deprecated and will be removed in future releases. "
+            "Use unquoted true or false instead.",
+            ci->values[0].value.string, ci->key);
+
+    if (IS_TRUE(ci->values[0].value.string))
+      *ret_bool = 1;
+    else if (IS_FALSE(ci->values[0].value.string))
+      *ret_bool = 0;
+    else {
+      ERROR("cf_util_get_boolean: Cannot parse string value `%s' of the `%s' "
+            "option as a boolean value.",
+            ci->values[0].value.string, ci->key);
+      return (-1);
+    }
+    break;
+  }
 
   return (0);
 } /* }}} int cf_util_get_boolean */