summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 938f678)
raw | patch | inline | side by side (parent: 938f678)
author | octo <octo> | |
Sat, 10 Jun 2006 11:01:05 +0000 (11:01 +0000) | ||
committer | octo <octo> | |
Sat, 10 Jun 2006 11:01:05 +0000 (11:01 +0000) |
collectd dies when the port is forwarded using ssh and then the server exits.
Apparently ssh doesn't anser with a connection refused right away which may
result in problems..
This revision adds some debug messages and handles `EOF' correctly (when
reading).
Apparently ssh doesn't anser with a connection refused right away which may
result in problems..
This revision adds some debug messages and handles `EOF' correctly (when
reading).
src/apcups.c | patch | blob | history |
diff --git a/src/apcups.c b/src/apcups.c
index 977b793918c200406a026649c2fbdf1ec0b66477..e2ad70cb0c4e6c243fc79f7d9a4021c9b283084a 100644 (file)
--- a/src/apcups.c
+++ b/src/apcups.c
{
nread = read (*fd, ptr, nleft);
- if (nread == -1 && (errno == EINTR || errno == EAGAIN))
+ if ((nread < 0) && (errno == EINTR || errno == EAGAIN))
continue;
- if (nread == -1)
+ if (nread < 0)
{
*fd = -1;
- syslog (LOG_ERR, "apcups plugin: write failed: %s", strerror (errno));
+ DBG ("Reading from socket failed failed: %s; *fd = -1;", strerror (errno));
+ syslog (LOG_ERR, "apcups plugin: Reading from socket failed failed: %s", strerror (errno));
return (-1);
}
+ if (nread == 0)
+ {
+ DBG ("Received EOF. Closing socket %i.", *fd);
+ close (*fd);
+ *fd = -1;
+ return (nbytes - nleft);
+ }
+
nleft -= nread;
ptr += nread;
}
{
nwritten = write (*fd, ptr, nleft);
- if ((nwritten == -1) && ((errno == EAGAIN) || (errno == EINTR)))
+ if ((nwritten < 0) && ((errno == EAGAIN) || (errno == EINTR)))
continue;
- if (nwritten == -1)
+ if (nwritten < 0)
{
- syslog (LOG_ERR, "Writing to socket failed: %s", strerror (errno));
*fd = -1;
+ DBG ("Writing to socket failed: %s; *fd = -1;", strerror (errno));
+ syslog (LOG_ERR, "apcups plugin: Writing to socket failed: %s", strerror (errno));
return (-1);
}
assert (*fd >= 0);
+ DBG ("Gracefully shutting down socket %i.", *fd);
+
/* send EOF sentinel */
write_nbytes (fd, &pktsiz, sizeof (short));
*fd = -1;
}
-
/*
* Open a TCP connection to the UPS network server
* Returns -1 on error
return (-1);
}
- DBG ("Done opening a socket: %i", sd);
+ DBG ("Done opening a socket %i", sd);
return (sd);
} /* int net_open (char *host, char *service, int port) */
short packet_size;
assert (len > 0);
+ assert (*sockfd >= 0);
/* send short containing size of data packet */
packet_size = htons ((short) len);
value = atof (tokptr);
PRINT_VALUE (key, value);
- DBG ("key = %s; value = %f;", key, value);
if (strcmp ("LINEV", key) == 0)
apcups_detail->linev = value;
{
syslog (LOG_WARNING, "apcups plugin: Error reading from socket");
return (-1);
- } else {
+ }
+ else
+ {
/* close the opened socket */
- net_close(&sockfd);
+ net_close (&sockfd);
}
return (0);