X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fonewire.c;h=8bb2d8161de5b3c145556da1f2be0575d95f97b8;hb=03af72c5ef8b98ddfcab87ea44b764f5b0e165aa;hp=51e6407137b0f2c8bc64598f822cac804c5a9fab;hpb=aedf67e69cbe93a6925fd1004a7c8b990aed4b0a;p=collectd.git diff --git a/src/onewire.c b/src/onewire.c index 51e64071..8bb2d816 100644 --- a/src/onewire.c +++ b/src/onewire.c @@ -20,6 +20,7 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" #include "utils_ignorelist.h" @@ -176,11 +177,11 @@ static int direct_list_insert(const char * config) { regmatch_t pmatch[3]; size_t nmatch = 3; - direct_access_element_t *element = NULL; + direct_access_element_t *element; DEBUG ("onewire plugin: direct_list_insert <%s>", config); - element = (direct_access_element_t *) malloc (sizeof(*element)); + element = malloc (sizeof (*element)); if (element == NULL) { ERROR ("onewire plugin: direct_list_insert - cannot allocate element"); @@ -338,7 +339,6 @@ static int cow_read_values (const char *path, const char *name, value_t values[1]; value_list_t vl = VALUE_LIST_INIT; int success = 0; - size_t i; if (sensor_list != NULL) { @@ -354,11 +354,12 @@ static int cow_read_values (const char *path, const char *name, sstrncpy (vl.plugin, "onewire", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, name, sizeof (vl.plugin_instance)); - for (i = 0; i < family_info->features_num; i++) + for (size_t i = 0; i < family_info->features_num; i++) { char *buffer; size_t buffer_size; int status; + char errbuf[1024]; char file[4096]; char *endptr; @@ -373,8 +374,8 @@ static int cow_read_values (const char *path, const char *name, 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); @@ -415,11 +416,11 @@ static int cow_read_ds2409 (const char *path) int status; status = ssnprintf (subpath, sizeof (subpath), "%s/main", path); - if ((status > 0) && (status < sizeof (subpath))) + if ((status > 0) && (status < (int) sizeof (subpath))) cow_read_bus (subpath); status = ssnprintf (subpath, sizeof (subpath), "%s/aux", path); - if ((status > 0) && (status < sizeof (subpath))) + if ((status > 0) && (status < (int) sizeof (subpath))) cow_read_bus (subpath); return (0); @@ -430,6 +431,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; @@ -439,8 +441,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", @@ -459,7 +461,7 @@ static int cow_read_bus (const char *path) else status = ssnprintf (subpath, sizeof (subpath), "%s/%s", path, buffer_ptr); - if ((status <= 0) || (status >= sizeof (subpath))) + if ((status <= 0) || (status >= (int) sizeof (subpath))) continue; for (i = 0; i < ow_family_features_num; i++) @@ -498,6 +500,7 @@ static int cow_simple_read (void) char *buffer; size_t buffer_size; int status; + char errbuf[1024]; char *endptr; direct_access_element_t *traverse; @@ -514,9 +517,9 @@ static int cow_simple_read (void) status = OW_get (traverse->path, &buffer, &buffer_size); if (status < 0) { - ERROR ("onewire plugin: OW_get (%s) failed. status = %#x;", + ERROR ("onewire plugin: OW_get (%s) failed. status = %s;", traverse->path, - status); + sstrerror(errno, errbuf, sizeof (errbuf))); return (-1); } DEBUG ("onewire plugin: Read onewire device %s as %s", traverse->path, buffer); @@ -590,7 +593,7 @@ static int cow_shutdown (void) static int cow_init (void) { int status; - struct timespec cb_interval; + char errbuf[1024]; if (device_g == NULL) { @@ -602,15 +605,12 @@ static int cow_init (void) 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); } - CDTIME_T_TO_TIMESPEC (ow_interval, &cb_interval); - plugin_register_complex_read (/* group = */ NULL, "onewire", cow_read, - (ow_interval != 0) ? &cb_interval : NULL, - /* user data = */ NULL); + ow_interval, /* user data = */ NULL); plugin_register_shutdown ("onewire", cow_shutdown); return (0);