From: Ruben Kerkhof Date: Fri, 5 Aug 2016 11:17:32 +0000 (+0200) Subject: Merge branch 'collectd-5.5' X-Git-Tag: collectd-5.6.0~111 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=958f7776a2daaa1a8664aded0a2c1d717c2f5909;hp=42c129f80a181553ac08b6e8d3484a845c674a07;p=collectd.git Merge branch 'collectd-5.5' Conflicts: src/pyvalues.c --- diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index 2ccc68c2..1bee8cdd 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -1974,10 +1974,10 @@ int plugin_shutdown_all (void) llentry_t *le; int ret = 0; // Assume success. - stop_read_threads (); - destroy_all_callbacks (&list_init); + stop_read_threads (); + pthread_mutex_lock (&read_lock); llist_destroy (read_list); read_list = NULL; @@ -1985,6 +1985,10 @@ int plugin_shutdown_all (void) destroy_read_heap (); + /* blocks until all write threads have shut down. */ + stop_write_threads (); + + /* ask all plugins to write out the state they kept. */ plugin_flush (/* plugin = */ NULL, /* timeout = */ 0, /* identifier = */ NULL); @@ -2015,8 +2019,6 @@ int plugin_shutdown_all (void) plugin_set_ctx (old_ctx); } - stop_write_threads (); - /* Write plugins which use the `user_data' pointer usually need the * same data available to the flush callback. If this is the case, set * the free_function to NULL when registering the flush callback and to diff --git a/src/network.c b/src/network.c index 1b560c47..58ddb225 100644 --- a/src/network.c +++ b/src/network.c @@ -490,7 +490,7 @@ static int network_dispatch_notification (notification_t *n) /* {{{ */ } /* }}} int network_dispatch_notification */ #if HAVE_LIBGCRYPT -static void network_init_gcrypt (void) /* {{{ */ +static int network_init_gcrypt (void) /* {{{ */ { gcry_error_t err; @@ -498,7 +498,7 @@ static void network_init_gcrypt (void) /* {{{ */ * Because you can't know in a library whether another library has * already initialized the library */ if (gcry_control (GCRYCTL_ANY_INITIALIZATION_P)) - return; + return (0); /* http://www.gnupg.org/documentation/manuals/gcrypt/Multi_002dThreading.html * To ensure thread-safety, it's important to set GCRYCTL_SET_THREAD_CBS @@ -512,7 +512,7 @@ static void network_init_gcrypt (void) /* {{{ */ if (err) { ERROR ("network plugin: gcry_control (GCRYCTL_SET_THREAD_CBS) failed: %s", gcry_strerror (err)); - abort (); + return (-1); } # endif @@ -522,11 +522,12 @@ static void network_init_gcrypt (void) /* {{{ */ if (err) { ERROR ("network plugin: gcry_control (GCRYCTL_INIT_SECMEM) failed: %s", gcry_strerror (err)); - abort (); + return (-1); } gcry_control (GCRYCTL_INITIALIZATION_FINISHED); -} /* }}} void network_init_gcrypt */ + return (0); +} /* }}} int network_init_gcrypt */ static gcry_cipher_hd_t network_get_aes256_cypher (sockent_t *se, /* {{{ */ const void *iv, size_t iv_size, const char *username) @@ -2061,7 +2062,12 @@ static int sockent_init_crypto (sockent_t *se) /* {{{ */ { if (se->data.client.security_level > SECURITY_LEVEL_NONE) { - network_init_gcrypt (); + if (network_init_gcrypt () < 0) + { + ERROR ("network plugin: Cannot configure client socket with " + "security: Failed to initialize crypto library."); + return (-1); + } if ((se->data.client.username == NULL) || (se->data.client.password == NULL)) @@ -2081,7 +2087,12 @@ static int sockent_init_crypto (sockent_t *se) /* {{{ */ { if (se->data.server.security_level > SECURITY_LEVEL_NONE) { - network_init_gcrypt (); + if (network_init_gcrypt () < 0) + { + ERROR ("network plugin: Cannot configure server socket with " + "security: Failed to initialize crypto library."); + return (-1); + } if (se->data.server.auth_file == NULL) { @@ -2880,6 +2891,11 @@ static int network_write (const data_set_t *ds, const value_list_t *vl, { int status; + /* listen_loop is set to non-zero in the shutdown callback, which is + * guaranteed to be called *after* all the write threads have been shut + * down. */ + assert (listen_loop == 0); + if (!check_send_okay (vl)) { #if COLLECT_DEBUG @@ -3434,7 +3450,11 @@ static int network_init (void) have_init = 1; #if HAVE_LIBGCRYPT - network_init_gcrypt (); + if (network_init_gcrypt () < 0) + { + ERROR ("network plugin: Failed to initialize crypto library."); + return (-1); + } #endif if (network_config_stats) diff --git a/src/pyvalues.c b/src/pyvalues.c index bd2088dc..a7cb7923 100644 --- a/src/pyvalues.c +++ b/src/pyvalues.c @@ -552,19 +552,22 @@ static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) { for (size_t i = 0; i < size; ++i) { PyObject *item, *num; item = PySequence_Fast_GET_ITEM(values, (int) i); /* Borrowed reference. */ - if (ds->ds->type == DS_TYPE_COUNTER) { + switch (ds->ds[i].type) { + case DS_TYPE_COUNTER: num = PyNumber_Long(item); /* New reference. */ if (num != NULL) { value[i].counter = PyLong_AsUnsignedLongLong(num); Py_XDECREF(num); } - } else if (ds->ds->type == DS_TYPE_GAUGE) { + break; + case DS_TYPE_GAUGE: num = PyNumber_Float(item); /* New reference. */ if (num != NULL) { value[i].gauge = PyFloat_AsDouble(num); Py_XDECREF(num); } - } else if (ds->ds->type == DS_TYPE_DERIVE) { + break; + case DS_TYPE_DERIVE: /* This might overflow without raising an exception. * Not much we can do about it */ num = PyNumber_Long(item); /* New reference. */ @@ -572,7 +575,8 @@ static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) { value[i].derive = PyLong_AsLongLong(num); Py_XDECREF(num); } - } else if (ds->ds->type == DS_TYPE_ABSOLUTE) { + break; + case DS_TYPE_ABSOLUTE: /* This might overflow without raising an exception. * Not much we can do about it */ num = PyNumber_Long(item); /* New reference. */ @@ -580,9 +584,10 @@ static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) { value[i].absolute = PyLong_AsUnsignedLongLong(num); Py_XDECREF(num); } - } else { + break; + default: free(value); - PyErr_Format(PyExc_RuntimeError, "unknown data type %d for %s", ds->ds->type, value_list.type); + PyErr_Format(PyExc_RuntimeError, "unknown data type %d for %s", ds->ds[i].type, value_list.type); return NULL; } if (PyErr_Occurred() != NULL) { @@ -656,19 +661,22 @@ static PyObject *Values_write(Values *self, PyObject *args, PyObject *kwds) { for (size_t i = 0; i < size; ++i) { PyObject *item, *num; item = PySequence_Fast_GET_ITEM(values, i); /* Borrowed reference. */ - if (ds->ds->type == DS_TYPE_COUNTER) { + switch (ds->ds[i].type) { + case DS_TYPE_COUNTER: num = PyNumber_Long(item); /* New reference. */ if (num != NULL) { value[i].counter = PyLong_AsUnsignedLongLong(num); Py_XDECREF(num); } - } else if (ds->ds->type == DS_TYPE_GAUGE) { + break; + case DS_TYPE_GAUGE: num = PyNumber_Float(item); /* New reference. */ if (num != NULL) { value[i].gauge = PyFloat_AsDouble(num); Py_XDECREF(num); } - } else if (ds->ds->type == DS_TYPE_DERIVE) { + break; + case DS_TYPE_DERIVE: /* This might overflow without raising an exception. * Not much we can do about it */ num = PyNumber_Long(item); /* New reference. */ @@ -676,7 +684,8 @@ static PyObject *Values_write(Values *self, PyObject *args, PyObject *kwds) { value[i].derive = PyLong_AsLongLong(num); Py_XDECREF(num); } - } else if (ds->ds->type == DS_TYPE_ABSOLUTE) { + break; + case DS_TYPE_ABSOLUTE: /* This might overflow without raising an exception. * Not much we can do about it */ num = PyNumber_Long(item); /* New reference. */ @@ -684,9 +693,10 @@ static PyObject *Values_write(Values *self, PyObject *args, PyObject *kwds) { value[i].absolute = PyLong_AsUnsignedLongLong(num); Py_XDECREF(num); } - } else { + break; + default: free(value); - PyErr_Format(PyExc_RuntimeError, "unknown data type %d for %s", ds->ds->type, value_list.type); + PyErr_Format(PyExc_RuntimeError, "unknown data type %d for %s", ds->ds[i].type, value_list.type); return NULL; } if (PyErr_Occurred() != NULL) {