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.
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
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) {
int mappings_cnt = 0;
const char *require_version = NULL;
+ rrd_thread_init();
/* clear any previous errors */
rrd_clear_error();
{
int status;
+ rrd_thread_init();
status = read_options (argc, argv);
if (status != 0)
{
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);
struct optparse options;
int opt;
+ rrd_thread_init();
/* Fix CWE-457 */
memset(&rrd, 0, sizeof(rrd_t));
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) {
#include <assert.h>
#include <errno.h>
+#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
return NULL;
}
+void rrd_thread_init(void)
+{
+#if !GLIB_CHECK_VERSION(2, 32, 0)
+ if (!g_thread_supported())
+ g_thread_init(NULL);
+#endif
+}
{0}
};
+ rrd_thread_init();
rrd_graph_init(&im);
rrd_parsetime("end-24h", &start_tv);