From: Sebastian Harl Date: Sun, 19 Oct 2014 16:22:09 +0000 (+0200) Subject: write_graphite plugin: Improved error reporting when connecting to the server. X-Git-Tag: collectd-5.3.2~27^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f5d2a5e24045a0a145408b20d0a28557b4c9d3f5;p=collectd.git write_graphite plugin: Improved error reporting when connecting to the server. --- diff --git a/src/write_graphite.c b/src/write_graphite.c index 99c6f4d8..392d5700 100644 --- 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; + char connerr[1024] = ""; + 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); - 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; @@ -217,11 +226,12 @@ static int wg_callback_init (struct wg_callback *cb) 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