projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #2660 from pbostley/master
[collectd.git]
/
src
/
apcups.c
diff --git
a/src/apcups.c
b/src/apcups.c
index
f6ee2db
..
262fa42
100644
(file)
--- a/
src/apcups.c
+++ b/
src/apcups.c
@@
-119,10
+119,8
@@
static int net_open(char const *node, char const *service) {
status = getaddrinfo(node, service, &ai_hints, &ai_return);
if (status != 0) {
status = getaddrinfo(node, service, &ai_hints, &ai_return);
if (status != 0) {
- char errbuf[1024];
INFO("apcups plugin: getaddrinfo failed: %s",
INFO("apcups plugin: getaddrinfo failed: %s",
- (status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : gai_strerror(status));
+ (status == EAI_SYSTEM) ? STRERRNO : gai_strerror(status));
return -1;
}
return -1;
}
@@
-147,9
+145,7
@@
static int net_open(char const *node, char const *service) {
if (status != 0) /* `connect(2)' failed */
{
if (status != 0) /* `connect(2)' failed */
{
- char errbuf[1024];
- INFO("apcups plugin: connect failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ INFO("apcups plugin: connect failed: %s", STRERRNO);
close(sd);
return -1;
}
close(sd);
return -1;
}
@@
-240,7
+236,8
@@
static int apc_query_server(char const *node, char const *service,
char recvline[1024];
char *tokptr;
char *toksaveptr;
char recvline[1024];
char *tokptr;
char *toksaveptr;
- _Bool retry = 1;
+ int try
+ = 0;
int status;
#if APCMAIN
int status;
#if APCMAIN
@@
-250,7
+247,7
@@
static int apc_query_server(char const *node, char const *service,
#define PRINT_VALUE(name, val) /**/
#endif
#define PRINT_VALUE(name, val) /**/
#endif
- while (
retry
) {
+ while (
1
) {
if (global_sockfd < 0) {
global_sockfd = net_open(node, service);
if (global_sockfd < 0) {
if (global_sockfd < 0) {
global_sockfd = net_open(node, service);
if (global_sockfd < 0) {
@@
-262,10
+259,11
@@
static int apc_query_server(char const *node, char const *service,
status = net_send(&global_sockfd, "status", strlen("status"));
if (status != 0) {
status = net_send(&global_sockfd, "status", strlen("status"));
if (status != 0) {
- /* net_send
is closing
the socket on error. */
+ /* net_send
closes
the socket on error. */
assert(global_sockfd < 0);
assert(global_sockfd < 0);
- if (retry) {
- retry = 0;
+ if (try == 0) {
+ try
+ ++;
count_retries++;
continue;
}
count_retries++;
continue;
}
@@
-275,7
+273,7
@@
static int apc_query_server(char const *node, char const *service,
}
break;
}
break;
- } /* while (
retry
) */
+ } /* while (
1
) */
/* When collectd's collection interval is larger than apcupsd's
* timeout, we would have to retry / re-connect each iteration. Try to
/* When collectd's collection interval is larger than apcupsd's
* timeout, we would have to retry / re-connect each iteration. Try to
@@
-341,9
+339,7
@@
static int apc_query_server(char const *node, char const *service,
net_shutdown(&global_sockfd);
if (n < 0) {
net_shutdown(&global_sockfd);
if (n < 0) {
- char errbuf[1024];
- ERROR("apcups plugin: Reading from socket failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("apcups plugin: Reading from socket failed: %s", STRERROR(status));
return -1;
}
return -1;
}
@@
-421,13
+417,11
@@
static int apcups_read(void) {
.linefreq = NAN,
};
.linefreq = NAN,
};
- int status =
- apc_query_server(conf_node == NULL ? APCUPS_DEFAULT_NODE : conf_node,
- conf_service, &apcups_detail);
+ int status = apc_query_server(conf_node, conf_service, &apcups_detail);
+
if (status != 0) {
if (status != 0) {
- DEBUG("apcups plugin: apc_query_server (\"%s\", \"%s\") = %d",
- conf_node == NULL ? APCUPS_DEFAULT_NODE : conf_node, conf_service,
- status);
+ DEBUG("apcups plugin: apc_query_server (\"%s\", \"%s\") = %d", conf_node,
+ conf_service, status);
return status;
}
return status;
}
@@
-436,8
+430,19
@@
static int apcups_read(void) {
return 0;
} /* apcups_read */
return 0;
} /* apcups_read */
+static int apcups_init(void) {
+ if (conf_node == NULL)
+ conf_node = APCUPS_DEFAULT_NODE;
+
+ if (conf_service == NULL)
+ conf_service = APCUPS_DEFAULT_SERVICE;
+
+ return 0;
+} /* apcups_init */
+
void module_register(void) {
plugin_register_complex_config("apcups", apcups_config);
void module_register(void) {
plugin_register_complex_config("apcups", apcups_config);
+ plugin_register_init("apcups", apcups_init);
plugin_register_read("apcups", apcups_read);
plugin_register_shutdown("apcups", apcups_shutdown);
} /* void module_register */
plugin_register_read("apcups", apcups_read);
plugin_register_shutdown("apcups", apcups_shutdown);
} /* void module_register */