#! /bin/sh /usr/share/dpatch/dpatch-run ## bts770683_curl_init.dpatch by Jeremy Katz ## ## DP: Call curl_global_init() in _init of plugins using curl. ## DP: ## DP: curl_global_init() or curl_easy_init() has to be called in the init ## DP: callback of plugins using curl while collectd still runs single ## DP: threaded. Else, collectd may crash with a segfault due to concurrent ## DP: memory access by curl. ## DP: ## DP: Upstream bug report: ## DP: https://github.com/collectd/collectd/issues/526 @DPATCH@ diff a/src/apache.c b/src/apache.c --- a/src/apache.c +++ b/src/apache.c @@ -702,9 +702,18 @@ static int apache_read_host (user_data_t *user_data) /* {{{ */ return (0); } /* }}} int apache_read_host */ +static int apache_init (void) /* {{{ */ +{ + /* Call this while collectd is still single-threaded to avoid + * initialization issues in libgcrypt. */ + curl_global_init (CURL_GLOBAL_SSL); + return (0); +} /* }}} int apache_init */ + void module_register (void) { plugin_register_complex_config ("apache", config); + plugin_register_init ("apache", apache_init); } /* void module_register */ /* vim: set sw=8 noet fdm=marker : */ diff a/src/curl.c b/src/curl.c --- a/src/curl.c +++ b/src/curl.c @@ -566,6 +566,7 @@ static int cc_init (void) /* {{{ */ INFO ("curl plugin: No pages have been defined."); return (-1); } + curl_global_init (CURL_GLOBAL_SSL); return (0); } /* }}} int cc_init */ diff --git a/src/curl_json.c b/src/curl_json.c index 24e1df1..0948962 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -882,9 +882,18 @@ static int cj_read (user_data_t *ud) /* {{{ */ return cj_curl_perform (db, db->curl); } /* }}} int cj_read */ +static int cj_init (void) /* {{{ */ +{ + /* Call this while collectd is still single-threaded to avoid + * initialization issues in libgcrypt. */ + curl_global_init (CURL_GLOBAL_SSL); + return (0); +} /* }}} int cj_init */ + void module_register (void) { plugin_register_complex_config ("curl_json", cj_config); + plugin_register_init ("curl_json", cj_init); } /* void module_register */ /* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/src/curl_xml.c b/src/curl_xml.c index b941f02..e31e73d 100644 --- a/src/curl_xml.c +++ b/src/curl_xml.c @@ -926,9 +926,18 @@ static int cx_config (oconfig_item_t *ci) /* {{{ */ return (0); } /* }}} int cx_config */ +static int cx_init (void) /* {{{ */ +{ + /* Call this while collectd is still single-threaded to avoid + * initialization issues in libgcrypt. */ + curl_global_init (CURL_GLOBAL_SSL); + return (0); +} /* }}} int cx_init */ + void module_register (void) { plugin_register_complex_config ("curl_xml", cx_config); + plugin_register_init ("curl_xml", cx_init); } /* void module_register */ /* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/src/write_http.c b/src/write_http.c index 62c73b0..04c637b 100644 --- a/src/write_http.c +++ b/src/write_http.c @@ -656,9 +656,18 @@ static int wh_config (oconfig_item_t *ci) /* {{{ */ return (0); } /* }}} int wh_config */ +static int wh_init (void) /* {{{ */ +{ + /* Call this while collectd is still single-threaded to avoid + * initialization issues in libgcrypt. */ + curl_global_init (CURL_GLOBAL_SSL); + return (0); +} /* }}} int wh_init */ + void module_register (void) /* {{{ */ { plugin_register_complex_config ("write_http", wh_config); + plugin_register_init ("write_http", wh_init); } /* }}} void module_register */ /* vim: set fdm=marker sw=8 ts=8 tw=78 et : */