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);
{
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;
+ }
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;
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. "
- "The last error was: %s", node, service,
- sstrerror (errno, errbuf, sizeof (errbuf)));
+ "The last error was: %s", node, service, connerr);
return (-1);
}
else