Merge branch 'collectd-5.7'
[collectd.git] / src / onewire.c
index 2901b78..407e857 100644 (file)
@@ -277,7 +277,6 @@ static int cow_load_config(const char *key, const char *value) {
 
 static int cow_read_values(const char *path, const char *name,
                            const ow_family_features_t *family_info) {
-  value_t values[1];
   value_list_t vl = VALUE_LIST_INIT;
   int success = 0;
 
@@ -287,10 +286,6 @@ static int cow_read_values(const char *path, const char *name,
       return 0;
   }
 
-  vl.values = values;
-  vl.values_len = 1;
-
-  sstrncpy(vl.host, hostname_g, sizeof(vl.host));
   sstrncpy(vl.plugin, "onewire", sizeof(vl.plugin));
   sstrncpy(vl.plugin_instance, name, sizeof(vl.plugin_instance));
 
@@ -298,6 +293,7 @@ static int cow_read_values(const char *path, const char *name,
     char *buffer;
     size_t buffer_size;
     int status;
+    char errbuf[1024];
 
     char file[4096];
     char *endptr;
@@ -311,14 +307,15 @@ static int cow_read_values(const char *path, const char *name,
     DEBUG("Start reading onewire device %s", file);
     status = OW_get(file, &buffer, &buffer_size);
     if (status < 0) {
-      ERROR("onewire plugin: OW_get (%s/%s) failed. status = %#x;", path,
-            family_info->features[i].filename, status);
+      ERROR("onewire plugin: OW_get (%s/%s) failed. error = %s;", path,
+            family_info->features[i].filename,
+            sstrerror(errno, errbuf, sizeof(errbuf)));
       return (-1);
     }
     DEBUG("Read onewire device %s as %s", file, buffer);
 
     endptr = NULL;
-    values[0].gauge = strtod(buffer, &endptr);
+    gauge_t g = strtod(buffer, &endptr);
     if (endptr == NULL) {
       ERROR("onewire plugin: Buffer is not a number: %s", buffer);
       continue;
@@ -328,6 +325,9 @@ static int cow_read_values(const char *path, const char *name,
     sstrncpy(vl.type_instance, family_info->features[i].type_instance,
              sizeof(vl.type_instance));
 
+    vl.values = &(value_t){.gauge = g};
+    vl.values_len = 1;
+
     plugin_dispatch_values(&vl);
     success++;
 
@@ -365,6 +365,7 @@ static int cow_read_bus(const char *path) {
   char *buffer;
   size_t buffer_size;
   int status;
+  char errbuf[1024];
 
   char *buffer_ptr;
   char *dummy;
@@ -373,7 +374,8 @@ static int cow_read_bus(const char *path) {
 
   status = OW_get(path, &buffer, &buffer_size);
   if (status < 0) {
-    ERROR("onewire plugin: OW_get (%s) failed. status = %#x;", path, status);
+    ERROR("onewire plugin: OW_get (%s) failed. error = %s;", path,
+          sstrerror(errno, errbuf, sizeof(errbuf)));
     return (-1);
   }
   DEBUG("onewire plugin: OW_get (%s) returned: %s", path, buffer);
@@ -420,34 +422,30 @@ static int cow_read_bus(const char *path) {
  */
 
 static int cow_simple_read(void) {
-  value_t values[1];
   value_list_t vl = VALUE_LIST_INIT;
   char *buffer;
   size_t buffer_size;
   int status;
+  char errbuf[1024];
   char *endptr;
   direct_access_element_t *traverse;
 
   /* traverse list and check entries */
   for (traverse = direct_list; traverse != NULL; traverse = traverse->next) {
-    vl.values = values;
-    vl.values_len = 1;
-
-    sstrncpy(vl.host, hostname_g, sizeof(vl.host));
     sstrncpy(vl.plugin, "onewire", sizeof(vl.plugin));
     sstrncpy(vl.plugin_instance, traverse->address, sizeof(vl.plugin_instance));
 
     status = OW_get(traverse->path, &buffer, &buffer_size);
     if (status < 0) {
-      ERROR("onewire plugin: OW_get (%s) failed. status = %#x;", traverse->path,
-            status);
+      ERROR("onewire plugin: OW_get (%s) failed. status = %s;", traverse->path,
+            sstrerror(errno, errbuf, sizeof(errbuf)));
       return (-1);
     }
     DEBUG("onewire plugin: Read onewire device %s as %s", traverse->path,
           buffer);
 
     endptr = NULL;
-    values[0].gauge = strtod(buffer, &endptr);
+    gauge_t g = strtod(buffer, &endptr);
     if (endptr == NULL) {
       ERROR("onewire plugin: Buffer is not a number: %s", buffer);
       continue;
@@ -456,6 +454,9 @@ static int cow_simple_read(void) {
     sstrncpy(vl.type, traverse->file, sizeof(vl.type));
     sstrncpy(vl.type_instance, "", sizeof(""));
 
+    vl.values = &(value_t){.gauge = g};
+    vl.values_len = 1;
+
     plugin_dispatch_values(&vl);
     free(buffer);
   } /* for (traverse) */
@@ -506,6 +507,7 @@ static int cow_shutdown(void) {
 
 static int cow_init(void) {
   int status;
+  char errbuf[1024];
 
   if (device_g == NULL) {
     ERROR("onewire plugin: cow_init: No device configured.");
@@ -515,7 +517,8 @@ static int cow_init(void) {
   DEBUG("onewire plugin: about to init device <%s>.", device_g);
   status = (int)OW_init(device_g);
   if (status != 0) {
-    ERROR("onewire plugin: OW_init(%s) failed: %i.", device_g, status);
+    ERROR("onewire plugin: OW_init(%s) failed: %s.", device_g,
+          sstrerror(errno, errbuf, sizeof(errbuf)));
     return (1);
   }
 
@@ -531,5 +534,3 @@ void module_register(void) {
   plugin_register_config("onewire", cow_load_config, config_keys,
                          config_keys_num);
 }
-
-/* vim: set sw=2 sts=2 ts=8 et fdm=marker cindent : */