summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ba7e9af)
raw | patch | inline | side by side (parent: ba7e9af)
author | Florian Forster <octo@collectd.org> | |
Thu, 13 Sep 2012 08:04:26 +0000 (10:04 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Thu, 13 Sep 2012 08:19:10 +0000 (10:19 +0200) |
src/apcups.c | patch | blob | history |
diff --git a/src/apcups.c b/src/apcups.c
index a0629d5f6ae0a87e13b08f1e53f6d69b0c1a85f3..d6a35c50929842f04b0641164e06a9127d4c9492 100644 (file)
--- a/src/apcups.c
+++ b/src/apcups.c
return (sd);
} /* int net_open (char *host, char *service, int port) */
-/*
+/*
* Receive a message from the other end. Each message consists of
* two packets. The first is a header that contains the size
* of the data that follows in the second packet.
/* get data size -- in short */
if (sread (*sockfd, (void *) &packet_size, sizeof (packet_size)) != 0)
{
+ close (*sockfd);
*sockfd = -1;
return (-1);
}
packet_size = ntohs (packet_size);
if (packet_size > buflen)
{
- DEBUG ("record length too large");
+ ERROR ("apcups plugin: Received %"PRIu16" bytes of payload "
+ "but have only %i bytes of buffer available.",
+ packet_size, buflen);
+ close (*sockfd);
+ *sockfd = -1;
return (-2);
}
/* now read the actual data */
if (sread (*sockfd, (void *) buf, packet_size) != 0)
{
+ close (*sockfd);
*sockfd = -1;
return (-1);
}
if (swrite (*sockfd, (void *) &packet_size, sizeof (packet_size)) != 0)
{
+ close (*sockfd);
*sockfd = -1;
return (-1);
}
/* send data packet */
if (swrite (*sockfd, (void *) buff, len) != 0)
{
+ close (*sockfd);
*sockfd = -1;
return (-2);
}
apcups_detail.timeleft = -1.0;
apcups_detail.itemp = -300.0;
apcups_detail.linefreq = -1.0;
-
+
status = apc_query_server (conf_host == NULL
? APCUPS_DEFAULT_HOST
: conf_host,
conf_port, &apcups_detail);
-
+
/*
* if we did not connect then do not bother submitting
* zeros. We want rrd files to have NAN.