X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Funixsock.c;h=8524beadd6fed8a30349179555ecd95e52f104e8;hb=0352eb93e70fb471d4975823db38147d2661f4bf;hp=95ccb9da38cb3f266df901bb4781ca8c0269fa44;hpb=a795179f29ec002bb2048635aef7642c994a911c;p=collectd.git diff --git a/src/unixsock.c b/src/unixsock.c index 95ccb9da..8524bead 100644 --- a/src/unixsock.c +++ b/src/unixsock.c @@ -144,47 +144,14 @@ static value_cache_t *cache_search (const char *name) return (vc); } /* value_cache_t *cache_search */ -static int cache_alloc_name (char *ret, int ret_len, - const char *hostname, - const char *plugin, const char *plugin_instance, - const char *type, const char *type_instance) -{ - int status; - - assert (plugin != NULL); - assert (type != NULL); - - if ((plugin_instance == NULL) || (strlen (plugin_instance) == 0)) - { - if ((type_instance == NULL) || (strlen (type_instance) == 0)) - status = snprintf (ret, ret_len, "%s/%s/%s", - hostname, plugin, type); - else - status = snprintf (ret, ret_len, "%s/%s/%s-%s", - hostname, plugin, type, type_instance); - } - else - { - if ((type_instance == NULL) || (strlen (type_instance) == 0)) - status = snprintf (ret, ret_len, "%s/%s-%s/%s", - hostname, plugin, plugin_instance, type); - else - status = snprintf (ret, ret_len, "%s/%s-%s/%s-%s", - hostname, plugin, plugin_instance, type, type_instance); - } - - if ((status < 1) || (status >= ret_len)) - return (-1); - return (0); -} /* int cache_alloc_name */ - static int cache_insert (const data_set_t *ds, const value_list_t *vl) { /* We're called from `cache_update' so we don't need to lock the mutex */ value_cache_t *vc; int i; - DEBUG ("ds->ds_num = %i; vl->values_len = %i;", + DEBUG ("unixsock plugin: cache_insert: ds->ds_num = %i;" + " vl->values_len = %i;", ds->ds_num, vl->values_len); assert (ds->ds_num == vl->values_len); @@ -221,12 +188,10 @@ static int cache_insert (const data_set_t *ds, const value_list_t *vl) return (-1); } - if (cache_alloc_name (vc->name, sizeof (vc->name), - vl->host, vl->plugin, vl->plugin_instance, - ds->type, vl->type_instance) != 0) + if (FORMAT_VL (vc->name, sizeof (vc->name), vl, ds)) { pthread_mutex_unlock (&cache_lock); - ERROR ("unixsock plugin: cache_alloc_name failed."); + ERROR ("unixsock plugin: FORMAT_VL failed."); free (vc->counter); free (vc->gauge); free (vc); @@ -271,10 +236,7 @@ static int cache_update (const data_set_t *ds, const value_list_t *vl) value_cache_t *vc; int i; - if (cache_alloc_name (name, sizeof (name), - vl->host, - vl->plugin, vl->plugin_instance, - ds->type, vl->type_instance) != 0) + if (FORMAT_VL (name, sizeof (name), vl, ds) != 0) return (-1); pthread_mutex_lock (&cache_lock); @@ -509,7 +471,7 @@ static int us_handle_getval (FILE *fh, char **fields, int fields_num) return (-1); } - status = cache_alloc_name (name, sizeof (name), + status = format_name (name, sizeof (name), hostname, plugin, plugin_instance, type, type_instance); /* FIXME: Send some response */ if (status != 0) @@ -883,7 +845,7 @@ static int us_write (const data_set_t *ds, const value_list_t *vl) return (0); } -void module_register (void) +void module_register (modreg_e load) { plugin_register_config ("unixsock", us_config, config_keys, config_keys_num);