projects
/
collectd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
31601e4
)
apcups plugin: Add function net_shutdown().
author
Florian Forster
<octo@collectd.org>
Thu, 13 Sep 2012 08:05:35 +0000
(10:05 +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
d6a35c5
..
60ba7f4
100644
(file)
--- a/
src/apcups.c
+++ b/
src/apcups.c
@@
-81,26
+81,31
@@
static const char *config_keys[] =
};
static int config_keys_num = 2;
};
static int config_keys_num = 2;
-/* Close the network connection */
-static int apcups_shutdown (void)
+static int net_shutdown (int *fd)
{
uint16_t packet_size = 0;
{
uint16_t packet_size = 0;
- if (
global_sockfd < 0
)
- return (
0
);
+ if (
(fd == NULL) || (*fd < 0)
)
+ return (
EINVAL
);
- DEBUG ("Gracefully shutting down socket %i.", global_sockfd);
+ swrite (*fd, (void *) &packet_size, sizeof (packet_size));
+ close (*fd);
+ *fd = -1;
- /* send EOF sentinel */
- swrite (global_sockfd, (void *) &packet_size, sizeof (packet_size));
+ return (0);
+} /* int net_shutdown */
- close (global_sockfd);
- global_sockfd = -1;
+/* Close the network connection */
+static int apcups_shutdown (void)
+{
+ if (global_sockfd < 0)
+ return (0);
+ net_shutdown (&global_sockfd);
return (0);
} /* int apcups_shutdown */
return (0);
} /* int apcups_shutdown */
-/*
+/*
* Open a TCP connection to the UPS network server
* Returns -1 on error
* Returns socket file descriptor otherwise
* Open a TCP connection to the UPS network server
* Returns -1 on error
* Returns socket file descriptor otherwise