]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Added missing GLib thread initialization. 787/head
authorSven Panne <svenpanne@gmail.com>
Wed, 24 May 2017 13:18:54 +0000 (15:18 +0200)
committerSven Panne <svenpanne@gmail.com>
Wed, 24 May 2017 13:48:18 +0000 (15:48 +0200)
Older GLib versions (< 2.32, e.g. the ones shipped with CentOS 5 and 6,
SLES11, Debian 6) need an explicit initialization to make things
thread-safe, see:

  https://developer.gnome.org/glib/stable/glib-Deprecated-Thread-APIs.html#g-thread-init

RRDtools didn't do that, so you get random crashes in clients and the
rrdcached on those systems.  Now we make sure that GLib is properly
initialized before calling into it.

src/rrd.h
src/rrd_create.c
src/rrd_daemon.c
src/rrd_graph.c
src/rrd_tune.c
src/rrd_update.c
src/rrd_utils.c
src/rrd_xport.c

index c42f915dc840e78dac2fc092f9ce3e4de0004a44..be153256f68d0622cd47e4434f871b1d337cd9a1 100644 (file)
--- a/src/rrd.h
+++ b/src/rrd.h
@@ -396,6 +396,7 @@ int       rrd_proc_start_end(
     const char * rrd_scaled_duration (const char * token,
                                       unsigned long divisor,
                                       unsigned long * valuep);
+    void rrd_thread_init(void);
 
 /*
  * The following functions are _internal_ functions needed to read the raw RRD
index 53eb74b4f94493655f3838f11f8bd91ae2008e5c..7c6f6efdf1a9bac55a2d25126d0e1dc618471a62 100644 (file)
@@ -88,6 +88,7 @@ int rrd_create(
     const char **sources_array = NULL;
     char *template = NULL;
     
+    rrd_thread_init();
     optparse_init(&options, argc, argv);
     while ((opt = optparse_long(&options, longopts, NULL)) != -1) {
         switch (opt) {
@@ -795,6 +796,7 @@ int rrd_create_r2(
     int mappings_cnt = 0;
     const char *require_version = NULL;
     
+    rrd_thread_init();
     /* clear any previous errors */
     rrd_clear_error();
 
index 23faeba0cdcddaf5e22ed47c77e076fff1c500b4..83925a12db022a48b1afaa296492c52289653b7c 100644 (file)
@@ -4697,6 +4697,7 @@ int main (int argc, char **argv)
 {
   int status;
 
+  rrd_thread_init();
   status = read_options (argc, argv);
   if (status != 0)
   {
index 20f946fcb977ad31abd9884ec03f995727e3f67f..a417fc6fbbe98093364430d575b394ff9871aaab 100644 (file)
@@ -4589,6 +4589,7 @@ rrd_info_t *rrd_graph_v(
     image_desc_t im;
     rrd_info_t *grinfo;
     struct optparse options;
+    rrd_thread_init();
     rrd_graph_init(&im);
     /* a dummy surface so that we can measure text sizes for placements */
     rrd_graph_options(argc, argv, &options, &im);
index 11a9ea219752ae2df0eeabc9955a404088d8cdec..07d455249b5a3155e1394ccc6715f589cc2b24da 100644 (file)
@@ -116,6 +116,7 @@ int rrd_tune(
     struct optparse options;
     int opt;
 
+    rrd_thread_init();
     /* Fix CWE-457 */
     memset(&rrd, 0, sizeof(rrd_t));
 
index b36593ead66e32e63baaea4e90333998f97ef4a2..4f257a18b4e66110ede951399ea95fa87c33414d 100644 (file)
@@ -682,6 +682,7 @@ int rrd_update(
     int       rc = -1;
     char     *opt_daemon = NULL;
 
+    rrd_thread_init();
     optparse_init(&options, argc, argv);
     while ((opt = optparse_long(&options,longopts,NULL)) != -1) {
         switch (opt) {
index 430d92e7d7c9f3d68dfbfb867ae2291b8d2d6aab..12e016eb6f162ecceb66a989902f6ae031a2bfb4 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <assert.h>
 #include <errno.h>
+#include <glib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
@@ -281,3 +282,10 @@ const char * rrd_scaled_duration (const char * token,
     return NULL;
 }
 
+void rrd_thread_init(void)
+{
+#if !GLIB_CHECK_VERSION(2, 32, 0)
+    if (!g_thread_supported())
+        g_thread_init(NULL);
+#endif
+}
index c63a9cc4e2880c94cb5321bba32ed0c05aa65f6b..2edc09e514991932dcd3cd2b70c5f965077c6294 100644 (file)
@@ -76,6 +76,7 @@ int rrd_xport(
         {0}
     };
 
+    rrd_thread_init();
     rrd_graph_init(&im);
 
     rrd_parsetime("end-24h", &start_tv);