projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
common.c: fix compilation on OpenBSD
[collectd.git]
/
src
/
sigrok.c
diff --git
a/src/sigrok.c
b/src/sigrok.c
index
ba3e406
..
4006455
100644
(file)
--- a/
src/sigrok.c
+++ b/
src/sigrok.c
@@
-1,6
+1,6
@@
/*
* collectd - src/sigrok.c
/*
* collectd - src/sigrok.c
- * Copyright (C) 2013 Bert Vermeulen
<bert@biot.com>
+ * Copyright (C) 2013 Bert Vermeulen
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@
-14,9
+14,13
@@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Bert Vermeulen <bert at biot.com>
*/
#include "collectd.h"
*/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "common.h"
#include "plugin.h"
@@
-24,7
+28,6
@@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
-#include <pthread.h>
#include <glib.h>
#include <libsigrok/libsigrok.h>
#include <glib.h>
#include <libsigrok/libsigrok.h>
@@
-67,13
+70,11
@@
static int sigrok_log_callback(void*cb_data __attribute__((unused)),
static int sigrok_config_device(oconfig_item_t *ci)
{
struct config_device *cfdev;
static int sigrok_config_device(oconfig_item_t *ci)
{
struct config_device *cfdev;
- int i;
- if (!(cfdev =
malloc(sizeof(struct config_device
)))) {
- ERROR("sigrok plugin:
malloc()
failed.");
+ if (!(cfdev =
calloc(1, sizeof(*cfdev
)))) {
+ ERROR("sigrok plugin:
calloc
failed.");
return -1;
}
return -1;
}
- memset(cfdev, 0, sizeof(*cfdev));
if (cf_util_get_string(ci, &cfdev->name)) {
free(cfdev);
WARNING("sigrok plugin: Invalid device name.");
if (cf_util_get_string(ci, &cfdev->name)) {
free(cfdev);
WARNING("sigrok plugin: Invalid device name.");
@@
-81,7
+82,7
@@
static int sigrok_config_device(oconfig_item_t *ci)
}
cfdev->min_dispatch_interval = DEFAULT_MIN_DISPATCH_INTERVAL;
}
cfdev->min_dispatch_interval = DEFAULT_MIN_DISPATCH_INTERVAL;
- for (i = 0; i < ci->children_num; i++) {
+ for (i
nt i
= 0; i < ci->children_num; i++) {
oconfig_item_t *item = ci->children + i;
if (!strcasecmp(item->key, "driver"))
cf_util_get_string(item, &cfdev->driver);
oconfig_item_t *item = ci->children + i;
if (!strcasecmp(item->key, "driver"))
cf_util_get_string(item, &cfdev->driver);
@@
-103,9
+104,7
@@
static int sigrok_config_device(oconfig_item_t *ci)
static int sigrok_config(oconfig_item_t *ci)
{
static int sigrok_config(oconfig_item_t *ci)
{
- int i;
-
- for (i = 0; i < ci->children_num; i++) {
+ for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *item = ci->children + i;
if (strcasecmp("LogLevel", item->key) == 0) {
int status;
oconfig_item_t *item = ci->children + i;
if (strcasecmp("LogLevel", item->key) == 0) {
int status;
@@
-133,9
+132,9
@@
static int sigrok_config(oconfig_item_t *ci)
return 0;
}
return 0;
}
-static char *sigrok_value_type(const struct sr_datafeed_analog *analog)
+static c
onst c
har *sigrok_value_type(const struct sr_datafeed_analog *analog)
{
{
- char *s;
+ c
onst c
har *s;
if (analog->mq == SR_MQ_VOLTAGE)
s = "voltage";
if (analog->mq == SR_MQ_VOLTAGE)
s = "voltage";
@@
-162,13
+161,12
@@
static void sigrok_feed_callback(const struct sr_dev_inst *sdi,
{
const struct sr_datafeed_analog *analog;
struct config_device *cfdev;
{
const struct sr_datafeed_analog *analog;
struct config_device *cfdev;
- GSList *l;
value_t value;
value_list_t vl = VALUE_LIST_INIT;
/* Find this device's configuration. */
cfdev = NULL;
value_t value;
value_list_t vl = VALUE_LIST_INIT;
/* Find this device's configuration. */
cfdev = NULL;
- for (l = config_devices; l; l = l->next) {
+ for (
GSList *
l = config_devices; l; l = l->next) {
cfdev = l->data;
if (cfdev->sdi == sdi) {
/* Found it. */
cfdev = l->data;
if (cfdev->sdi == sdi) {
/* Found it. */
@@
-233,14
+231,14
@@
static int sigrok_init_driver(struct config_device *cfdev,
drvopts = NULL;
if (cfdev->conn) {
drvopts = NULL;
if (cfdev->conn) {
- if (!(src = malloc(sizeof(
struct sr_config
))))
+ if (!(src = malloc(sizeof(
*src
))))
return -1;
src->key = SR_CONF_CONN;
src->data = g_variant_new_string(cfdev->conn);
drvopts = g_slist_append(drvopts, src);
}
if (cfdev->serialcomm) {
return -1;
src->key = SR_CONF_CONN;
src->data = g_variant_new_string(cfdev->conn);
drvopts = g_slist_append(drvopts, src);
}
if (cfdev->serialcomm) {
- if (!(src = malloc(sizeof(
struct sr_config
))))
+ if (!(src = malloc(sizeof(
*src
))))
return -1;
src->key = SR_CONF_SERIALCOMM;
src->data = g_variant_new_string(cfdev->serialcomm);
return -1;
src->key = SR_CONF_SERIALCOMM;
src->data = g_variant_new_string(cfdev->serialcomm);
@@
-357,10
+355,13
@@
static int sigrok_init(void)
return -1;
}
return -1;
}
- if ((status = plugin_thread_create(&sr_thread, NULL, sigrok_read_thread,
- NULL)) != 0) {
+ status = plugin_thread_create(&sr_thread, NULL, sigrok_read_thread,
+ NULL);
+ if (status != 0)
+ {
+ char errbuf[1024];
ERROR("sigrok plugin: Failed to create thread: %s.",
ERROR("sigrok plugin: Failed to create thread: %s.",
- s
trerror(status
));
+ s
strerror (errno, errbuf, sizeof (errbuf)
));
return -1;
}
sr_thread_running = TRUE;
return -1;
}
sr_thread_running = TRUE;