**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_ignorelist.h"
{
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");
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;
- size_t i;
if (sensor_list != NULL)
{
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));
- 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;
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);
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++;
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);
char *buffer;
size_t buffer_size;
int status;
+ char errbuf[1024];
char *buffer_ptr;
char *dummy;
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",
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++)
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;",
+ 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);
-
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);
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) */
static int cow_init (void)
{
int status;
- struct timespec cb_interval;
+ char errbuf[1024];
if (device_g == NULL)
{
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);