projects
/
collectd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
714522f
)
write_graphite plugin: Improved error reporting when connecting to the server.
author
Sebastian Harl
<sh@tokkee.org>
Sun, 19 Oct 2014 16:22:09 +0000
(18:22 +0200)
committer
Sebastian Harl
<sh@tokkee.org>
Sun, 19 Oct 2014 16:22:09 +0000
(18:22 +0200)
src/write_graphite.c
patch
|
blob
|
history
diff --git
a/src/write_graphite.c
b/src/write_graphite.c
index
99c6f4d
..
392d570
100644
(file)
--- a/
src/write_graphite.c
+++ b/
src/write_graphite.c
@@
-174,6
+174,8
@@
static int wg_callback_init (struct wg_callback *cb)
const char *node = cb->node ? cb->node : WG_DEFAULT_NODE;
const char *service = cb->service ? cb->service : WG_DEFAULT_SERVICE;
const char *node = cb->node ? cb->node : WG_DEFAULT_NODE;
const char *service = cb->service ? cb->service : WG_DEFAULT_SERVICE;
+ char connerr[1024] = "";
+
if (cb->sock_fd > 0)
return (0);
if (cb->sock_fd > 0)
return (0);
@@
-199,12
+201,19
@@
static int wg_callback_init (struct wg_callback *cb)
{
cb->sock_fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype,
ai_ptr->ai_protocol);
{
cb->sock_fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype,
ai_ptr->ai_protocol);
- if (cb->sock_fd < 0)
+ if (cb->sock_fd < 0) {
+ char errbuf[1024];
+ snprintf (connerr, sizeof (connerr), "failed to open socket: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
continue;
continue;
+ }
status = connect (cb->sock_fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
if (status != 0)
{
status = connect (cb->sock_fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
if (status != 0)
{
+ char errbuf[1024];
+ snprintf (connerr, sizeof (connerr), "failed to connect to remote "
+ "host: %s", sstrerror (errno, errbuf, sizeof (errbuf)));
close (cb->sock_fd);
cb->sock_fd = -1;
continue;
close (cb->sock_fd);
cb->sock_fd = -1;
continue;
@@
-217,11
+226,12
@@
static int wg_callback_init (struct wg_callback *cb)
if (cb->sock_fd < 0)
{
if (cb->sock_fd < 0)
{
- char errbuf[1024];
+ if (connerr[0] == '\0')
+ /* this should not happen but try to get a message anyway */
+ sstrerror (errno, connerr, sizeof (connerr));
c_complain (LOG_ERR, &cb->init_complaint,
"write_graphite plugin: Connecting to %s:%s failed. "
c_complain (LOG_ERR, &cb->init_complaint,
"write_graphite plugin: Connecting to %s:%s failed. "
- "The last error was: %s", node, service,
- sstrerror (errno, errbuf, sizeof (errbuf)));
+ "The last error was: %s", node, service, connerr);
return (-1);
}
else
return (-1);
}
else