From: Pierre-Yves Ritschard Date: Tue, 11 Nov 2014 18:39:58 +0000 (+0100) Subject: Merge pull request #765 from tokkee/sh/write-err X-Git-Tag: collectd-5.3.2~25 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=0e24ad12c7a741be3a6214d0712cad74c68d33f9;hp=de067db48b0f16b6678a900339801c6cb59681a3;p=collectd.git Merge pull request #765 from tokkee/sh/write-err Use the complain mechanism to report write failures. --- diff --git a/src/libcollectdclient/network_buffer.c b/src/libcollectdclient/network_buffer.c index 7b066204..61c7c22e 100644 --- a/src/libcollectdclient/network_buffer.c +++ b/src/libcollectdclient/network_buffer.c @@ -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); diff --git a/src/logfile.c b/src/logfile.c index 0f20f3ca..63448cb6 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -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); diff --git a/src/network.c b/src/network.c index a33d06e0..a2221e5b 100644 --- a/src/network.c +++ b/src/network.c @@ -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); diff --git a/src/syslog.c b/src/syslog.c index 4f5d0c4a..834ba79c 100644 --- a/src/syslog.c +++ b/src/syslog.c @@ -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) { 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