X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmqtt.c;h=315974b6f49a8b6b7d85a59427de1f0cc9a6026f;hb=55ffaf9ad7c8b180ac0192adb1a6ff6adc72c5a3;hp=6b76af97b9d7818349720e0cbcb828957ac44ea5;hpb=98bfe15ca31dc5deaf29b9fbcdfb5a4241ea677c;p=collectd.git diff --git a/src/mqtt.c b/src/mqtt.c index 6b76af97..315974b6 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -462,6 +462,7 @@ static int format_topic(char *buf, size_t buf_len, data_set_t const *ds, value_list_t const *vl, mqtt_client_conf_t *conf) { char name[MQTT_MAX_TOPIC_SIZE]; int status; + char *c; if ((conf->topic_prefix == NULL) || (conf->topic_prefix[0] == 0)) return (FORMAT_VL(buf, buf_len, vl)); @@ -474,6 +475,10 @@ static int format_topic(char *buf, size_t buf_len, data_set_t const *ds, if ((status < 0) || (((size_t)status) >= buf_len)) return (ENOMEM); + while((c = strchr(buf, '#')) || (c = strchr(buf, '+'))) { + *c = '_'; + } + return (0); } /* int format_topic */ @@ -604,9 +609,9 @@ static int mqtt_config_publisher(oconfig_item_t *ci) { } ssnprintf(cb_name, sizeof(cb_name), "mqtt/%s", conf->name); - user_data_t user_data = {.data = conf}; - - plugin_register_write(cb_name, mqtt_write, &user_data); + plugin_register_write(cb_name, mqtt_write, &(user_data_t){ + .data = conf, + }); return (0); } /* mqtt_config_publisher */ @@ -735,7 +740,8 @@ static int mqtt_init(void) { status = plugin_thread_create(&subscribers[i]->thread, /* attrs = */ NULL, /* func = */ subscribers_thread, - /* args = */ subscribers[i]); + /* args = */ subscribers[i], + /* name = */ "mqtt"); if (status != 0) { char errbuf[1024]; ERROR("mqtt plugin: pthread_create failed: %s",