Merge branch 'collectd-4.10' into collectd-5.0
[collectd.git] / src / network.c
index 3cf2227..1f8fe0a 100644 (file)
@@ -3366,9 +3366,17 @@ static int network_init (void)
        have_init = 1;
 
 #if HAVE_LIBGCRYPT
-       gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
-       gcry_control (GCRYCTL_INIT_SECMEM, 32768, 0);
-       gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
+    /* http://lists.gnupg.org/pipermail/gcrypt-devel/2003-August/000458.html
+     * Because you can't know in a library whether another library has
+     * already initialized the library
+     */
+    if (!gcry_control (GCRYCTL_ANY_INITIALIZATION_P))
+    {
+        gcry_check_version(NULL); /* before calling any other functions */
+        gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
+        gcry_control (GCRYCTL_INIT_SECMEM, 32768, 0);
+        gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
+    }
 #endif
 
        if (network_config_stats != 0)