Merge pull request #765 from tokkee/sh/write-err
authorPierre-Yves Ritschard <pyr@spootnik.org>
Tue, 11 Nov 2014 18:39:58 +0000 (19:39 +0100)
committerPierre-Yves Ritschard <pyr@spootnik.org>
Tue, 11 Nov 2014 18:39:58 +0000 (19:39 +0100)
Use the complain mechanism to report write failures.

src/libcollectdclient/network_buffer.c
src/logfile.c
src/network.c
src/syslog.c
src/write_graphite.c

index 7b06620..61c7c22 100644 (file)
@@ -54,7 +54,9 @@
 /* Re enable deprecation warnings */
 #  pragma GCC diagnostic warning "-Wdeprecated-declarations"
 # endif
+# if GCRYPT_VERSION_NUMBER < 0x010600
 GCRY_THREAD_OPTION_PTHREAD_IMPL;
+# endif
 #endif
 
 #include "collectd/network_buffer.h"
@@ -131,7 +133,9 @@ static _Bool have_gcrypt (void) /* {{{ */
   need_init = 0;
 
 #if HAVE_LIBGCRYPT
+# if GCRYPT_VERSION_NUMBER < 0x010600
   gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
+# endif
 
   if (!gcry_check_version (GCRYPT_VERSION))
     return (0);
index 0f20f3c..63448cb 100644 (file)
@@ -54,7 +54,11 @@ static int logfile_config (const char *key, const char *value)
 {
        if (0 == strcasecmp (key, "LogLevel")) {
                log_level = parse_log_severity(value);
-               if (log_level == -1) return 1; /* to keep previous behaviour */
+               if (log_level < 0) {
+                       log_level = LOG_INFO;
+                       ERROR ("logfile: invalid loglevel [%s] defaulting to 'info'", value);
+                       return (1);
+               }
        }
        else if (0 == strcasecmp (key, "File")) {
                sfree (log_file);
index a33d06e..a2221e5 100644 (file)
@@ -76,7 +76,9 @@
 /* Re enable deprecation warnings */
 #  pragma GCC diagnostic warning "-Wdeprecated-declarations"
 # endif
+# if GCRYPT_VERSION_NUMBER < 0x010600
 GCRY_THREAD_OPTION_PTHREAD_IMPL;
+# endif
 #endif
 
 #ifndef IPV6_ADD_MEMBERSHIP
@@ -508,7 +510,9 @@ static void network_init_gcrypt (void) /* {{{ */
   * above doesn't count, as it doesn't implicitly initalize Libgcrypt.
   *
   * tl;dr: keep all these gry_* statements in this exact order please. */
+# if GCRYPT_VERSION_NUMBER < 0x010600
   gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
+# endif
   gcry_check_version (NULL);
   gcry_control (GCRYCTL_INIT_SECMEM, 32768);
   gcry_control (GCRYCTL_INITIALIZATION_FINISHED);
index 4f5d0c4..834ba79 100644 (file)
@@ -48,7 +48,11 @@ static int sl_config (const char *key, const char *value)
        {
                log_level = parse_log_severity (value);
                if (log_level < 0)
+               {
+                       log_level = LOG_INFO;
+                       ERROR ("syslog: invalid loglevel [%s] defaulting to 'info'", value);
                        return (1);
+               }
        }
        else if (strcasecmp (key, "NotifyLevel") == 0)
        {
index 99c6f4d..392d570 100644 (file)
@@ -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