projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
write_sensu: use sstrncpy
[collectd.git]
/
src
/
ted.c
diff --git
a/src/ted.c
b/src/ted.c
index
cccb3db
..
b803681
100644
(file)
--- a/
src/ted.c
+++ b/
src/ted.c
@@
-39,8
+39,7
@@
#include "common.h"
#include "plugin.h"
#include "common.h"
#include "plugin.h"
-#if HAVE_TERMIOS_H && HAVE_SYS_IOCTL_H && HAVE_MATH_H
-#include <math.h>
+#if HAVE_TERMIOS_H && HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#include <termios.h>
#else
#include <sys/ioctl.h>
#include <termios.h>
#else
@@
-89,8
+88,8
@@
static int ted_read_value(double *ret_power, double *ret_voltage) {
status = write(fd, pkt_request, sizeof(pkt_request));
if (status <= 0) {
status = write(fd, pkt_request, sizeof(pkt_request));
if (status <= 0) {
- ERROR("ted plugin:
s
write failed.");
- return
(-1)
;
+ ERROR("ted plugin: write failed.");
+ return
-1
;
}
/* Loop until we find the end of the package */
}
/* Loop until we find the end of the package */
@@
-105,33
+104,29
@@
static int ted_read_value(double *ret_power, double *ret_voltage) {
{
WARNING("ted plugin: Timeout while waiting for file descriptor "
"to become ready.");
{
WARNING("ted plugin: Timeout while waiting for file descriptor "
"to become ready.");
- return
(-1)
;
+ return
-1
;
} else if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR))) {
/* Some signal or something. Start over.. */
continue;
} else if (status < 0) {
} else if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR))) {
/* Some signal or something. Start over.. */
continue;
} else if (status < 0) {
- char errbuf[1024];
- ERROR("ted plugin: select failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
- return (-1);
+ ERROR("ted plugin: select failed: %s", STRERRNO);
+ return -1;
}
receive_buffer_length = read(fd, receive_buffer, sizeof(receive_buffer));
if (receive_buffer_length < 0) {
}
receive_buffer_length = read(fd, receive_buffer, sizeof(receive_buffer));
if (receive_buffer_length < 0) {
- char errbuf[1024];
if ((errno == EAGAIN) || (errno == EINTR))
continue;
if ((errno == EAGAIN) || (errno == EINTR))
continue;
- ERROR("ted plugin: read(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
- return (-1);
+ ERROR("ted plugin: read(2) failed: %s", STRERRNO);
+ return -1;
} else if (receive_buffer_length == 0) {
/* Should we close the FD in this case? */
WARNING("ted plugin: Received EOF from file descriptor.");
} else if (receive_buffer_length == 0) {
/* Should we close the FD in this case? */
WARNING("ted plugin: Received EOF from file descriptor.");
- return
(-1)
;
+ return
-1
;
} else if (((size_t)receive_buffer_length) > sizeof(receive_buffer)) {
ERROR("ted plugin: read(2) returned invalid value %zi.",
receive_buffer_length);
} else if (((size_t)receive_buffer_length) > sizeof(receive_buffer)) {
ERROR("ted plugin: read(2) returned invalid value %zi.",
receive_buffer_length);
- return
(-1)
;
+ return
-1
;
}
/*
}
/*
@@
-176,7
+171,7
@@
static int ted_read_value(double *ret_power, double *ret_voltage) {
/* Check for errors inside the loop. */
if ((end_flag == 0) || (package_buffer_pos != EXPECTED_PACKAGE_LENGTH))
/* Check for errors inside the loop. */
if ((end_flag == 0) || (package_buffer_pos != EXPECTED_PACKAGE_LENGTH))
- return
(-1)
;
+ return
-1
;
/*
* Power is at positions 247 and 248 (LSB first) in [10kW].
/*
* Power is at positions 247 and 248 (LSB first) in [10kW].
@@
-191,7
+186,7
@@
static int ted_read_value(double *ret_power, double *ret_voltage) {
((int)package_buffer[251]));
/* success */
((int)package_buffer[251]));
/* success */
- return
(0)
;
+ return
0
;
} /* int ted_read_value */
static int ted_open_device(void) {
} /* int ted_read_value */
static int ted_open_device(void) {
@@
-199,7
+194,7
@@
static int ted_open_device(void) {
struct termios options;
if (fd >= 0)
struct termios options;
if (fd >= 0)
- return
(0)
;
+ return
0
;
dev = DEFAULT_DEVICE;
if (conf_device != NULL)
dev = DEFAULT_DEVICE;
if (conf_device != NULL)
@@
-208,7
+203,7
@@
static int ted_open_device(void) {
fd = open(dev, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
if (fd < 0) {
ERROR("ted plugin: Unable to open device %s.", dev);
fd = open(dev, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
if (fd < 0) {
ERROR("ted plugin: Unable to open device %s.", dev);
- return
(-1)
;
+ return
-1
;
}
/* Get the current options for the port... */
}
/* Get the current options for the port... */
@@
-225,7
+220,7
@@
static int ted_open_device(void) {
tcsetattr(fd, TCSANOW, &options);
INFO("ted plugin: Successfully opened %s.", dev);
tcsetattr(fd, TCSANOW, &options);
INFO("ted plugin: Successfully opened %s.", dev);
- return
(0)
;
+ return
0
;
} /* int ted_open_device */
static void ted_submit(const char *type, double value) {
} /* int ted_open_device */
static void ted_submit(const char *type, double value) {
@@
-249,15
+244,15
@@
static int ted_config(const char *key, const char *value) {
tmp = atoi(value);
if (tmp < 0) {
WARNING("ted plugin: Invalid retry count: %i", tmp);
tmp = atoi(value);
if (tmp < 0) {
WARNING("ted plugin: Invalid retry count: %i", tmp);
- return
(1)
;
+ return
1
;
}
conf_retries = tmp;
} else {
ERROR("ted plugin: Unknown config option: %s", key);
}
conf_retries = tmp;
} else {
ERROR("ted plugin: Unknown config option: %s", key);
- return
(-1)
;
+ return
-1
;
}
}
- return
(0)
;
+ return
0
;
} /* int ted_config */
static int ted_read(void) {
} /* int ted_config */
static int ted_read(void) {
@@
-267,7
+262,7
@@
static int ted_read(void) {
status = ted_open_device();
if (status != 0)
status = ted_open_device();
if (status != 0)
- return
(-1)
;
+ return
-1
;
power = NAN;
voltage = NAN;
power = NAN;
voltage = NAN;
@@
-278,12
+273,12
@@
static int ted_read(void) {
}
if (status != 0)
}
if (status != 0)
- return
(-1)
;
+ return
-1
;
ted_submit("power", power);
ted_submit("voltage", voltage);
ted_submit("power", power);
ted_submit("voltage", voltage);
- return
(0)
;
+ return
0
;
} /* int ted_read */
static int ted_shutdown(void) {
} /* int ted_read */
static int ted_shutdown(void) {
@@
-292,7
+287,7
@@
static int ted_shutdown(void) {
fd = -1;
}
fd = -1;
}
- return
(0)
;
+ return
0
;
} /* int ted_shutdown */
void module_register(void) {
} /* int ted_shutdown */
void module_register(void) {
@@
-300,5
+295,3
@@
void module_register(void) {
plugin_register_read("ted", ted_read);
plugin_register_shutdown("ted", ted_shutdown);
} /* void module_register */
plugin_register_read("ted", ted_read);
plugin_register_shutdown("ted", ted_shutdown);
} /* void module_register */
-
-/* vim: set sw=4 et : */