From ccc69cc64e79170e09eb3eae9cb9d2d22c6f06e6 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 17 Jun 2011 10:25:48 +0200 Subject: [PATCH] rrdcached plugin: Register write/flush only if DaemonAddress has been given. Else, the write callback would remove itself on the first call. This operation, however, is not thread-safe as access to the write list is not synchronized. Thus, removing the callback at that point leads to random segfaults. --- src/rrdcached.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/rrdcached.c b/src/rrdcached.c index a3927156..f53ccad7 100644 --- a/src/rrdcached.c +++ b/src/rrdcached.c @@ -49,6 +49,14 @@ static rrdcreate_config_t rrdcreate_config = /* consolidation_functions_num = */ 0 }; +/* + * Prototypes. + */ +static int rc_write (const data_set_t *ds, const value_list_t *vl, + user_data_t __attribute__((unused)) *user_data); +static int rc_flush (__attribute__((unused)) cdtime_t timeout, + const char *identifier, __attribute__((unused)) user_data_t *ud); + static int value_list_to_string (char *buffer, int buffer_len, const data_set_t *ds, const value_list_t *vl) { @@ -227,6 +235,11 @@ static int rc_config (oconfig_item_t *ci) continue; } } + + if (daemon_address != NULL) { + plugin_register_write ("rrdcached", rc_write, /* user_data = */ NULL); + plugin_register_flush ("rrdcached", rc_flush, /* user_data = */ NULL); + } return (0); } /* int rc_config */ @@ -466,8 +479,6 @@ void module_register (void) { plugin_register_complex_config ("rrdcached", rc_config); plugin_register_init ("rrdcached", rc_init); - plugin_register_write ("rrdcached", rc_write, /* user_data = */ NULL); - plugin_register_flush ("rrdcached", rc_flush, /* user_data = */ NULL); plugin_register_shutdown ("rrdcached", rc_shutdown); } /* void module_register */ -- 2.30.2