Merge branch 'collectd-5.7' into collectd-5.8
authorFlorian Forster <octo@collectd.org>
Thu, 30 Nov 2017 16:11:49 +0000 (17:11 +0100)
committerFlorian Forster <octo@collectd.org>
Thu, 30 Nov 2017 16:11:49 +0000 (17:11 +0100)
1  2 
src/aggregation.c
src/ping.c
src/target_set.c

diff --combined src/aggregation.c
@@@ -93,16 -93,16 +93,16 @@@ static _Bool agg_is_regex(char const *s
    size_t len;
  
    if (str == NULL)
 -    return (0);
 +    return 0;
  
    len = strlen(str);
    if (len < 3)
 -    return (0);
 +    return 0;
  
    if ((str[0] == '/') && (str[len - 1] == '/'))
 -    return (1);
 +    return 1;
    else
 -    return (0);
 +    return 0;
  } /* }}} _Bool agg_is_regex */
  
  static void agg_destroy(aggregation_t *agg) /* {{{ */
@@@ -200,15 -200,17 +200,15 @@@ static int agg_instance_create_name(agg
        sstrncpy(inst->ident.plugin_instance, AGG_FUNC_PLACEHOLDER,
                 sizeof(inst->ident.plugin_instance));
      else if (strcmp("", tmp_plugin) != 0)
 -      ssnprintf(inst->ident.plugin_instance,
 -                sizeof(inst->ident.plugin_instance), "%s-%s", tmp_plugin,
 -                AGG_FUNC_PLACEHOLDER);
 +      snprintf(inst->ident.plugin_instance, sizeof(inst->ident.plugin_instance),
 +               "%s-%s", tmp_plugin, AGG_FUNC_PLACEHOLDER);
      else if (strcmp("", tmp_plugin_instance) != 0)
 -      ssnprintf(inst->ident.plugin_instance,
 -                sizeof(inst->ident.plugin_instance), "%s-%s",
 -                tmp_plugin_instance, AGG_FUNC_PLACEHOLDER);
 +      snprintf(inst->ident.plugin_instance, sizeof(inst->ident.plugin_instance),
 +               "%s-%s", tmp_plugin_instance, AGG_FUNC_PLACEHOLDER);
      else
 -      ssnprintf(inst->ident.plugin_instance,
 -                sizeof(inst->ident.plugin_instance), "%s-%s-%s", tmp_plugin,
 -                tmp_plugin_instance, AGG_FUNC_PLACEHOLDER);
 +      snprintf(inst->ident.plugin_instance, sizeof(inst->ident.plugin_instance),
 +               "%s-%s-%s", tmp_plugin, tmp_plugin_instance,
 +               AGG_FUNC_PLACEHOLDER);
    }
  
    /* Type */
  
  #undef COPY_FIELD
  
 -  return (0);
 +  return 0;
  } /* }}} int agg_instance_create_name */
  
  /* Create a new aggregation instance. */
@@@ -234,7 -236,7 +234,7 @@@ static agg_instance_t *agg_instance_cre
    inst = calloc(1, sizeof(*inst));
    if (inst == NULL) {
      ERROR("aggregation plugin: calloc() failed.");
 -    return (NULL);
 +    return NULL;
    }
    pthread_mutex_init(&inst->lock, /* attr = */ NULL);
  
          agg_instance_destroy(inst);                                            \
          free(inst);                                                            \
          ERROR("aggregation plugin: calloc() failed.");                         \
 -        return (NULL);                                                         \
 +        return NULL;                                                           \
        }                                                                        \
      }                                                                          \
    } while (0)
    agg_instance_list_head = inst;
    pthread_mutex_unlock(&agg_instance_list_lock);
  
 -  return (inst);
 +  return inst;
  } /* }}} agg_instance_t *agg_instance_create */
  
  /* Update the num, sum, min, max, ... fields of the aggregation instance, if
@@@ -289,7 -291,7 +289,7 @@@ static int agg_instance_update(agg_inst
            "data source. This is currently not supported by this plugin. "
            "Sorry.",
            ds->type);
 -    return (EINVAL);
 +    return EINVAL;
    }
  
    rate = uc_get_rate(ds, vl);
      FORMAT_VL(ident, sizeof(ident), vl);
      ERROR("aggregation plugin: Unable to read the current rate of \"%s\".",
            ident);
 -    return (ENOENT);
 +    return ENOENT;
    }
  
    if (isnan(rate[0])) {
      sfree(rate);
 -    return (0);
 +    return 0;
    }
  
    pthread_mutex_lock(&inst->lock);
    pthread_mutex_unlock(&inst->lock);
  
    sfree(rate);
 -  return (0);
 +  return 0;
  } /* }}} int agg_instance_update */
  
  static int agg_instance_read_func(agg_instance_t *inst, /* {{{ */
       * COUNTER or a DERIVE, it will return EAGAIN. Catch this and handle
       * gracefully. */
      if (status == EAGAIN)
 -      return (0);
 +      return 0;
  
      WARNING("aggregation plugin: rate_to_value failed with status %i.", status);
 -    return (-1);
 +    return -1;
    }
  
    vl->values = &v;
    vl->values = NULL;
    vl->values_len = 0;
  
 -  return (0);
 +  return 0;
  } /* }}} int agg_instance_read_func */
  
  static int agg_instance_read(agg_instance_t *inst, cdtime_t t) /* {{{ */
    vl.meta = meta_data_create();
    if (vl.meta == NULL) {
      ERROR("aggregation plugin: meta_data_create failed.");
 -    return (-1);
 +    return -1;
    }
    meta_data_add_boolean(vl.meta, "aggregation:created", 1);
  
      READ_FUNC(average, (inst->sum / ((gauge_t)inst->num)));
      READ_FUNC(min, inst->min);
      READ_FUNC(max, inst->max);
-     READ_FUNC(stddev, sqrt((((gauge_t)inst->num) * inst->squares_sum) -
-                            (inst->sum * inst->sum)) /
-                           ((gauge_t)inst->num));
+     READ_FUNC(stddev,
+               sqrt((((gauge_t)inst->num) * inst->squares_sum) -
+                    (inst->sum * inst->sum)) /
+                   ((gauge_t)inst->num));
    }
  
    /* Reset internal state. */
    meta_data_destroy(vl.meta);
    vl.meta = NULL;
  
 -  return (0);
 +  return 0;
  } /* }}} int agg_instance_read */
  
  /* lookup_class_callback_t for utils_vl_lookup */
@@@ -428,7 -431,7 +429,7 @@@ static void *agg_lookup_class_callback(
                                         data_set_t const *ds,
                                         value_list_t const *vl,
                                         void *user_class) {
 -  return (agg_instance_create(ds, vl, (aggregation_t *)user_class));
 +  return agg_instance_create(ds, vl, (aggregation_t *)user_class);
  } /* }}} void *agg_class_callback */
  
  /* lookup_obj_callback_t for utils_vl_lookup */
@@@ -436,7 -439,7 +437,7 @@@ static int agg_lookup_obj_callback(data
                                     value_list_t const *vl,
                                     __attribute__((unused)) void *user_class,
                                     void *user_obj) {
 -  return (agg_instance_update((agg_instance_t *)user_obj, ds, vl));
 +  return agg_instance_update((agg_instance_t *)user_obj, ds, vl);
  } /* }}} int agg_lookup_obj_callback */
  
  /* lookup_free_class_callback_t for utils_vl_lookup */
@@@ -499,19 -502,15 +500,15 @@@ static int agg_config_handle_group_by(o
                value);
    } /* for (ci->values) */
  
 -  return (0);
 +  return 0;
  } /* }}} int agg_config_handle_group_by */
  
  static int agg_config_aggregation(oconfig_item_t *ci) /* {{{ */
  {
-   aggregation_t *agg;
-   _Bool is_valid;
-   int status;
-   agg = calloc(1, sizeof(*agg));
+   aggregation_t *agg = calloc(1, sizeof(*agg));
    if (agg == NULL) {
      ERROR("aggregation plugin: calloc failed.");
 -    return (-1);
 +    return -1;
    }
  
    sstrncpy(agg->ident.host, "/.*/", sizeof(agg->ident.host));
  
    for (int i = 0; i < ci->children_num; i++) {
      oconfig_item_t *child = ci->children + i;
+     int status = 0;
  
      if (strcasecmp("Host", child->key) == 0)
-       cf_util_get_string_buffer(child, agg->ident.host,
-                                 sizeof(agg->ident.host));
+       status = cf_util_get_string_buffer(child, agg->ident.host,
+                                          sizeof(agg->ident.host));
      else if (strcasecmp("Plugin", child->key) == 0)
-       cf_util_get_string_buffer(child, agg->ident.plugin,
-                                 sizeof(agg->ident.plugin));
+       status = cf_util_get_string_buffer(child, agg->ident.plugin,
+                                          sizeof(agg->ident.plugin));
      else if (strcasecmp("PluginInstance", child->key) == 0)
-       cf_util_get_string_buffer(child, agg->ident.plugin_instance,
-                                 sizeof(agg->ident.plugin_instance));
+       status = cf_util_get_string_buffer(child, agg->ident.plugin_instance,
+                                          sizeof(agg->ident.plugin_instance));
      else if (strcasecmp("Type", child->key) == 0)
-       cf_util_get_string_buffer(child, agg->ident.type,
-                                 sizeof(agg->ident.type));
+       status = cf_util_get_string_buffer(child, agg->ident.type,
+                                          sizeof(agg->ident.type));
      else if (strcasecmp("TypeInstance", child->key) == 0)
-       cf_util_get_string_buffer(child, agg->ident.type_instance,
-                                 sizeof(agg->ident.type_instance));
+       status = cf_util_get_string_buffer(child, agg->ident.type_instance,
+                                          sizeof(agg->ident.type_instance));
      else if (strcasecmp("SetHost", child->key) == 0)
-       cf_util_get_string(child, &agg->set_host);
+       status = cf_util_get_string(child, &agg->set_host);
      else if (strcasecmp("SetPlugin", child->key) == 0)
-       cf_util_get_string(child, &agg->set_plugin);
+       status = cf_util_get_string(child, &agg->set_plugin);
      else if (strcasecmp("SetPluginInstance", child->key) == 0)
-       cf_util_get_string(child, &agg->set_plugin_instance);
+       status = cf_util_get_string(child, &agg->set_plugin_instance);
      else if (strcasecmp("SetTypeInstance", child->key) == 0)
-       cf_util_get_string(child, &agg->set_type_instance);
+       status = cf_util_get_string(child, &agg->set_type_instance);
      else if (strcasecmp("GroupBy", child->key) == 0)
-       agg_config_handle_group_by(child, agg);
+       status = agg_config_handle_group_by(child, agg);
      else if (strcasecmp("CalculateNum", child->key) == 0)
-       cf_util_get_boolean(child, &agg->calc_num);
+       status = cf_util_get_boolean(child, &agg->calc_num);
      else if (strcasecmp("CalculateSum", child->key) == 0)
-       cf_util_get_boolean(child, &agg->calc_sum);
+       status = cf_util_get_boolean(child, &agg->calc_sum);
      else if (strcasecmp("CalculateAverage", child->key) == 0)
-       cf_util_get_boolean(child, &agg->calc_average);
+       status = cf_util_get_boolean(child, &agg->calc_average);
      else if (strcasecmp("CalculateMinimum", child->key) == 0)
-       cf_util_get_boolean(child, &agg->calc_min);
+       status = cf_util_get_boolean(child, &agg->calc_min);
      else if (strcasecmp("CalculateMaximum", child->key) == 0)
-       cf_util_get_boolean(child, &agg->calc_max);
+       status = cf_util_get_boolean(child, &agg->calc_max);
      else if (strcasecmp("CalculateStddev", child->key) == 0)
-       cf_util_get_boolean(child, &agg->calc_stddev);
+       status = cf_util_get_boolean(child, &agg->calc_stddev);
      else
        WARNING("aggregation plugin: The \"%s\" key is not allowed inside "
                "<Aggregation /> blocks and will be ignored.",
                child->key);
-   }
+     if (status != 0) {
+       sfree(agg);
+       return status;
+     }
+   } /* for (int i = 0; i < ci->children_num; i++) */
  
    if (agg_is_regex(agg->ident.host))
      agg->regex_fields |= LU_GROUP_BY_HOST;
      agg->regex_fields |= LU_GROUP_BY_TYPE_INSTANCE;
  
    /* Sanity checking */
-   is_valid = 1;
+   _Bool is_valid = 1;
    if (strcmp("/.*/", agg->ident.type) == 0) /* {{{ */
    {
      ERROR("aggregation plugin: It appears you did not specify the required "
      is_valid = 0;
    } /* }}} */
  
-   if (!is_valid) /* {{{ */
-   {
+   if (!is_valid) { /* {{{ */
      sfree(agg);
 -    return (-1);
 +    return -1;
    } /* }}} */
  
-   status = lookup_add(lookup, &agg->ident, agg->group_by, agg);
+   int status = lookup_add(lookup, &agg->ident, agg->group_by, agg);
    if (status != 0) {
      ERROR("aggregation plugin: lookup_add failed with status %i.", status);
      sfree(agg);
 -    return (-1);
 +    return -1;
    }
  
    DEBUG("aggregation plugin: Successfully added aggregation: "
          "Type \"%s\", TypeInstance \"%s\")",
          agg->ident.host, agg->ident.plugin, agg->ident.plugin_instance,
          agg->ident.type, agg->ident.type_instance);
 -  return (0);
 +  return 0;
  } /* }}} int agg_config_aggregation */
  
  static int agg_config(oconfig_item_t *ci) /* {{{ */
      if (lookup == NULL) {
        pthread_mutex_unlock(&agg_instance_list_lock);
        ERROR("aggregation plugin: lookup_create failed.");
 -      return (-1);
 +      return -1;
      }
    }
  
  
    pthread_mutex_unlock(&agg_instance_list_lock);
  
 -  return (0);
 +  return 0;
  } /* }}} int agg_config */
  
  static int agg_read(void) /* {{{ */
     * Therefore we need to handle this case separately. */
    if (agg_instance_list_head == NULL) {
      pthread_mutex_unlock(&agg_instance_list_lock);
 -    return (0);
 +    return 0;
    }
  
    for (agg_instance_t *this = agg_instance_list_head; this != NULL;
  
    pthread_mutex_unlock(&agg_instance_list_lock);
  
 -  return ((success > 0) ? 0 : -1);
 +  return (success > 0) ? 0 : -1;
  } /* }}} int agg_read */
  
  static int agg_write(data_set_t const *ds, value_list_t const *vl, /* {{{ */
    (void)meta_data_get_boolean(vl->meta, "aggregation:created",
                                &created_by_aggregation);
    if (created_by_aggregation)
 -    return (0);
 +    return 0;
  
    if (lookup == NULL)
      status = ENOENT;
        status = 0;
    }
  
 -  return (status);
 +  return status;
  } /* }}} int agg_write */
  
  void module_register(void) {
    plugin_register_read("aggregation", agg_read);
    plugin_register_write("aggregation", agg_write, /* user_data = */ NULL);
  }
 -
 -/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */
diff --combined src/ping.c
@@@ -81,11 -81,11 +81,11 @@@ static double ping_interval = 1.0
  static double ping_timeout = 0.9;
  static int ping_max_missed = -1;
  
+ static pthread_mutex_t ping_lock = PTHREAD_MUTEX_INITIALIZER;
+ static pthread_cond_t ping_cond = PTHREAD_COND_INITIALIZER;
  static int ping_thread_loop = 0;
  static int ping_thread_error = 0;
  static pthread_t ping_thread_id;
- static pthread_mutex_t ping_lock = PTHREAD_MUTEX_INITIALIZER;
- static pthread_cond_t ping_cond = PTHREAD_COND_INITIALIZER;
  
  static const char *config_keys[] = {"Host",    "SourceAddress",
  #ifdef HAVE_OPING_1_3
@@@ -219,13 -219,11 +219,11 @@@ static int ping_dispatch_all(pingobj_t 
      } /* }}} ping_max_missed */
    }   /* }}} for (iter) */
  
 -  return (0);
 +  return 0;
  } /* }}} int ping_dispatch_all */
  
  static void *ping_thread(void *arg) /* {{{ */
  {
-   pingobj_t *pingobj = NULL;
    struct timeval tv_begin;
    struct timeval tv_end;
    struct timespec ts_wait;
  
    c_complain_t complaint = C_COMPLAIN_INIT_STATIC;
  
-   pthread_mutex_lock(&ping_lock);
-   pingobj = ping_construct();
+   pingobj_t *pingobj = ping_construct();
    if (pingobj == NULL) {
      ERROR("ping plugin: ping_construct failed.");
+     pthread_mutex_lock(&ping_lock);
      ping_thread_error = 1;
      pthread_mutex_unlock(&ping_lock);
 -    return ((void *)-1);
 +    return (void *)-1;
    }
  
    if (ping_source != NULL)
  
    if (count == 0) {
      ERROR("ping plugin: No host could be added to ping object. Giving up.");
+     pthread_mutex_lock(&ping_lock);
      ping_thread_error = 1;
      pthread_mutex_unlock(&ping_lock);
 -    return ((void *)-1);
 +    return (void *)-1;
    }
  
    /* Set up `ts_int' */
      ts_int.tv_nsec = (long)(temp_nsec * 1000000000L);
    }
  
+   pthread_mutex_lock(&ping_lock);
    while (ping_thread_loop > 0) {
-     int status;
      _Bool send_successful = 0;
  
      if (gettimeofday(&tv_begin, NULL) < 0) {
  
      pthread_mutex_unlock(&ping_lock);
  
-     status = ping_send(pingobj);
+     int status = ping_send(pingobj);
      if (status < 0) {
        c_complain(LOG_ERR, &complaint, "ping plugin: ping_send failed: %s",
                   ping_get_error(pingobj));
    pthread_mutex_unlock(&ping_lock);
    ping_destroy(pingobj);
  
 -  return ((void *)0);
 +  return (void *)0;
  } /* }}} void *ping_thread */
  
  static int start_thread(void) /* {{{ */
  
    if (ping_thread_loop != 0) {
      pthread_mutex_unlock(&ping_lock);
 -    return (0);
 +    return 0;
    }
  
    ping_thread_loop = 1;
      ping_thread_loop = 0;
      ERROR("ping plugin: Starting thread failed.");
      pthread_mutex_unlock(&ping_lock);
 -    return (-1);
 +    return -1;
    }
  
    pthread_mutex_unlock(&ping_lock);
 -  return (0);
 +  return 0;
  } /* }}} int start_thread */
  
  static int stop_thread(void) /* {{{ */
  
    if (ping_thread_loop == 0) {
      pthread_mutex_unlock(&ping_lock);
 -    return (-1);
 +    return -1;
    }
  
    ping_thread_loop = 0;
    ping_thread_error = 0;
    pthread_mutex_unlock(&ping_lock);
  
 -  return (status);
 +  return status;
  } /* }}} int stop_thread */
  
  static int ping_init(void) /* {{{ */
  {
    if (hostlist_head == NULL) {
      NOTICE("ping plugin: No hosts have been configured.");
 -    return (-1);
 +    return -1;
    }
  
    if (ping_timeout > ping_interval) {
    }
  #endif
  
 -  return (start_thread());
 +  return start_thread();
  } /* }}} int ping_init */
  
  static int config_set_string(const char *name, /* {{{ */
      char errbuf[1024];
      ERROR("ping plugin: Setting `%s' to `%s' failed: strdup failed: %s", name,
            value, sstrerror(errno, errbuf, sizeof(errbuf)));
 -    return (1);
 +    return 1;
    }
  
    if (*var != NULL)
      free(*var);
    *var = tmp;
 -  return (0);
 +  return 0;
  } /* }}} int config_set_string */
  
  static int ping_config(const char *key, const char *value) /* {{{ */
        char errbuf[1024];
        ERROR("ping plugin: malloc failed: %s",
              sstrerror(errno, errbuf, sizeof(errbuf)));
 -      return (1);
 +      return 1;
      }
  
      host = strdup(value);
        sfree(hl);
        ERROR("ping plugin: strdup failed: %s",
              sstrerror(errno, errbuf, sizeof(errbuf)));
 -      return (1);
 +      return 1;
      }
  
      hl->host = host;
    } else if (strcasecmp(key, "SourceAddress") == 0) {
      int status = config_set_string(key, &ping_source, value);
      if (status != 0)
 -      return (status);
 +      return status;
    }
  #ifdef HAVE_OPING_1_3
    else if (strcasecmp(key, "Device") == 0) {
      int status = config_set_string(key, &ping_device, value);
      if (status != 0)
 -      return (status);
 +      return status;
    }
  #endif
    else if (strcasecmp(key, "TTL") == 0) {
        ping_data = malloc(size + 1);
        if (ping_data == NULL) {
          ERROR("ping plugin: malloc failed.");
 -        return (1);
 +        return 1;
        }
  
        /* Note: By default oping is using constant string
      if (ping_max_missed < 0)
        INFO("ping plugin: MaxMissed < 0, disabled re-resolving of hosts");
    } else {
 -    return (-1);
 +    return -1;
    }
  
 -  return (0);
 +  return 0;
  } /* }}} int ping_config */
  
  static void submit(const char *host, const char *type, /* {{{ */
@@@ -581,7 -579,7 +579,7 @@@ static int ping_read(void) /* {{{ *
  
      start_thread();
  
 -    return (-1);
 +    return -1;
    } /* if (ping_thread_error != 0) */
  
    for (hostlist_t *hl = hostlist_head; hl != NULL; hl = hl->next) /* {{{ */
      submit(hl->host, "ping_droprate", droprate);
    } /* }}} for (hl = hostlist_head; hl != NULL; hl = hl->next) */
  
 -  return (0);
 +  return 0;
  } /* }}} int ping_read */
  
  static int ping_shutdown(void) /* {{{ */
  
    INFO("ping plugin: Shutting down thread.");
    if (stop_thread() < 0)
 -    return (-1);
 +    return -1;
  
    hl = hostlist_head;
    while (hl != NULL) {
      ping_data = NULL;
    }
  
 -  return (0);
 +  return 0;
  } /* }}} int ping_shutdown */
  
  void module_register(void) {
    plugin_register_read("ping", ping_read);
    plugin_register_shutdown("ping", ping_shutdown);
  } /* void module_register */
 -
 -/* vim: set sw=2 sts=2 et fdm=marker : */
diff --combined src/target_set.c
@@@ -70,13 -70,13 +70,13 @@@ static int ts_util_get_key_and_string_w
      ERROR("ts_util_get_key_and_string_wo_strdup: The %s option requires "
            "exactly two string arguments.",
            ci->key);
 -    return (-1);
 +    return -1;
    }
  
    *ret_key = ci->values[0].value.string;
    *ret_string = ci->values[1].value.string;
  
 -  return (0);
 +  return 0;
  } /* }}} int ts_util_get_key_and_string_wo_strdup */
  
  static int ts_config_add_string(char **dest, /* {{{ */
  
    status = cf_util_get_string(ci, &tmp);
    if (status != 0)
 -    return (status);
 +    return status;
  
    if (!may_be_empty && (strlen(tmp) == 0)) {
      ERROR("Target `set': The `%s' option does not accept empty strings.",
            ci->key);
      sfree(tmp);
 -    return (-1);
 +    return -1;
    }
  
    *dest = tmp;
 -  return (0);
 +  return 0;
  } /* }}} int ts_config_add_string */
  
  static int ts_config_add_meta(meta_data_t **dest, /* {{{ */
  
    status = ts_util_get_key_and_string_wo_strdup(ci, &key, &string);
    if (status != 0)
 -    return (status);
 +    return status;
  
    if (strlen(key) == 0) {
      ERROR("Target `set': The `%s' option does not accept empty string as "
            "first argument.",
            ci->key);
 -    return (-1);
 +    return -1;
    }
  
    if (!may_be_empty && (strlen(string) == 0)) {
      ERROR("Target `set': The `%s' option does not accept empty string as "
            "second argument.",
            ci->key);
 -    return (-1);
 +    return -1;
    }
  
    if ((*dest) == NULL) {
      /* Create a new meta_data_t */
      if ((*dest = meta_data_create()) == NULL) {
        ERROR("Target `set': failed to create a meta data for `%s'.", ci->key);
 -      return (-ENOMEM);
 +      return -ENOMEM;
      }
    }
  
 -  return (meta_data_add_string(*dest, key, string));
 +  return meta_data_add_string(*dest, key, string);
  } /* }}} int ts_config_add_meta */
  
  static int ts_config_add_meta_delete(ts_key_list_t **dest, /* {{{ */
    entry = calloc(1, sizeof(*entry));
    if (entry == NULL) {
      ERROR("ts_config_add_meta_delete: calloc failed.");
 -    return (-ENOMEM);
 +    return -ENOMEM;
    }
  
    if (cf_util_get_string(ci, &entry->key) != 0) {
      ts_key_list_free(entry);
 -    return (-1); /* An error has already been reported. */
 +    return -1; /* An error has already been reported. */
    }
  
    if (strlen(entry->key) == 0) {
            "first argument.",
            ci->key);
      ts_key_list_free(entry);
 -    return (-1);
 +    return -1;
    }
  
    entry->next = *dest;
    *dest = entry;
  
 -  return (0);
 +  return 0;
  } /* }}} int ts_config_add_meta_delete */
  
  static void ts_subst(char *dest, size_t size, const char *string, /* {{{ */
        char *value_str;
        const char *key = meta_toc[i];
  
 -      ssnprintf(meta_name, sizeof(meta_name), "%%{meta:%s}", key);
 +      snprintf(meta_name, sizeof(meta_name), "%%{meta:%s}", key);
        if (meta_data_as_string(vl->meta, key, &value_str) != 0)
          continue;
  
@@@ -211,11 -211,11 +211,11 @@@ static int ts_destroy(void **user_data
    ts_data_t *data;
  
    if (user_data == NULL)
 -    return (-EINVAL);
 +    return -EINVAL;
  
    data = *user_data;
    if (data == NULL)
 -    return (0);
 +    return 0;
  
    free(data->host);
    free(data->plugin);
    ts_key_list_free(data->meta_delete);
    free(data);
  
 -  return (0);
 +  return 0;
  } /* }}} int ts_destroy */
  
  static int ts_create(const oconfig_item_t *ci, void **user_data) /* {{{ */
    data = calloc(1, sizeof(*data));
    if (data == NULL) {
      ERROR("ts_create: calloc failed.");
 -    return (-ENOMEM);
 +    return -ENOMEM;
    }
  
    data->host = NULL;
  
    if (status != 0) {
      ts_destroy((void *)&data);
 -    return (status);
 +    return status;
    }
  
    *user_data = data;
 -  return (0);
 +  return 0;
  } /* }}} int ts_create */
  
  static int ts_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */
    meta_data_t *new_meta = NULL;
  
    if ((ds == NULL) || (vl == NULL) || (user_data == NULL))
 -    return (-EINVAL);
 +    return -EINVAL;
  
    data = *user_data;
    if (data == NULL) {
      ERROR("Target `set': Invoke: `data' is NULL.");
 -    return (-EINVAL);
 +    return -EINVAL;
    }
  
    orig = *vl;
  
      if ((new_meta = meta_data_create()) == NULL) {
        ERROR("Target `set': failed to create replacement metadata.");
 -      return (-ENOMEM);
 +      return -ENOMEM;
      }
  
      int status = meta_data_toc(data->meta, &meta_toc);
      if (status < 0) {
        ERROR("Target `set': meta_data_toc failed with status %d.", status);
+       meta_data_destroy(new_meta);
        return status;
      }
      size_t meta_entries = (size_t)status;
                key);
          strarray_free(meta_toc, meta_entries);
          meta_data_destroy(new_meta);
 -        return (status);
 +        return status;
        }
  
        ts_subst(temp, sizeof(temp), string, &orig);
          ERROR("Target `set': Unable to set metadata value `%s'.", key);
          strarray_free(meta_toc, meta_entries);
          meta_data_destroy(new_meta);
 -        return (status);
 +        return status;
        }
      }
  
      meta_data_delete(vl->meta, l->key);
    }
  
 -  return (FC_TARGET_CONTINUE);
 +  return FC_TARGET_CONTINUE;
  } /* }}} int ts_invoke */
  
  void module_register(void) {
    tproc.invoke = ts_invoke;
    fc_register_target("set", tproc);
  } /* module_register */
 -
 -/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */