X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsigrok.c;h=e7aab7f34fc5b8056805909503356ebd1bd7a108;hb=cd2238b8b4f4ecd80c45862b5aeed3d3d73eddfe;hp=ba3e4062f0e9519544858ce982c0fc22c921a012;hpb=9b43c4ca7442e7886c1fbe339ce57f297872269f;p=collectd.git diff --git a/src/sigrok.c b/src/sigrok.c index ba3e4062..e7aab7f3 100644 --- a/src/sigrok.c +++ b/src/sigrok.c @@ -1,6 +1,6 @@ /* * collectd - src/sigrok.c - * Copyright (C) 2013 Bert Vermeulen + * 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 @@ -14,9 +14,13 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . + * + * Authors: + * Bert Vermeulen */ #include "collectd.h" + #include "common.h" #include "plugin.h" @@ -24,7 +28,6 @@ #include #include #include -#include #include #include @@ -69,11 +72,10 @@ 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; } - memset(cfdev, 0, sizeof(*cfdev)); if (cf_util_get_string(ci, &cfdev->name)) { free(cfdev); WARNING("sigrok plugin: Invalid device name."); @@ -133,9 +135,9 @@ static int sigrok_config(oconfig_item_t *ci) return 0; } -static char *sigrok_value_type(const struct sr_datafeed_analog *analog) +static const char *sigrok_value_type(const struct sr_datafeed_analog *analog) { - char *s; + const char *s; if (analog->mq == SR_MQ_VOLTAGE) s = "voltage"; @@ -233,14 +235,14 @@ static int sigrok_init_driver(struct config_device *cfdev, 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) { - 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); @@ -357,10 +359,13 @@ static int sigrok_init(void) 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.", - strerror(status)); + sstrerror (errno, errbuf, sizeof (errbuf))); return -1; } sr_thread_running = TRUE;