1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## bts770683_curl_init.dpatch by Jeremy Katz <jeremy@katzbox.net>
3 ##
4 ## DP: Call curl_global_init() in _init of plugins using curl.
5 ## DP:
6 ## DP: curl_global_init() or curl_easy_init() has to be called in the init
7 ## DP: callback of plugins using curl while collectd still runs single
8 ## DP: threaded. Else, collectd may crash with a segfault due to concurrent
9 ## DP: memory access by curl.
10 ## DP:
11 ## DP: Upstream bug report:
12 ## DP: https://github.com/collectd/collectd/issues/526
14 @DPATCH@
16 diff a/src/apache.c b/src/apache.c
17 --- a/src/apache.c
18 +++ b/src/apache.c
19 @@ -671,9 +671,18 @@ static int apache_read_host (user_data_t *user_data) /* {{{ */
20 return (0);
21 } /* }}} int apache_read_host */
23 +static int apache_init (void) /* {{{ */
24 +{
25 + /* Call this while collectd is still single-threaded to avoid
26 + * initialization issues in libgcrypt. */
27 + curl_global_init (CURL_GLOBAL_SSL);
28 + return (0);
29 +} /* }}} int apache_init */
30 +
31 void module_register (void)
32 {
33 plugin_register_complex_config ("apache", config);
34 + plugin_register_init ("apache", apache_init);
35 } /* void module_register */
37 /* vim: set sw=8 noet fdm=marker : */
38 diff a/src/curl.c b/src/curl.c
39 --- a/src/curl.c
40 +++ b/src/curl.c
41 @@ -569,6 +569,7 @@ static int cc_init (void) /* {{{ */
42 INFO ("curl plugin: No pages have been defined.");
43 return (-1);
44 }
45 + curl_global_init (CURL_GLOBAL_SSL);
46 return (0);
47 } /* }}} int cc_init */
49 diff a/src/curl_json.c b/src/curl_json.c
50 --- a/src/curl_json.c
51 +++ b/src/curl_json.c
52 @@ -957,9 +957,18 @@ static int cj_read (user_data_t *ud) /* {{{ */
53 return cj_perform (db);
54 } /* }}} int cj_read */
56 +static int cj_init (void) /* {{{ */
57 +{
58 + /* Call this while collectd is still single-threaded to avoid
59 + * initialization issues in libgcrypt. */
60 + curl_global_init (CURL_GLOBAL_SSL);
61 + return (0);
62 +} /* }}} int cj_init */
63 +
64 void module_register (void)
65 {
66 plugin_register_complex_config ("curl_json", cj_config);
67 + plugin_register_init ("curl_json", cj_init);
68 } /* void module_register */
70 /* vim: set sw=2 sts=2 et fdm=marker : */
71 diff a/src/curl_xml.c b/src/curl_xml.c
72 --- a/src/curl_xml.c
73 +++ b/src/curl_xml.c
74 @@ -1033,9 +1033,18 @@ static int cx_config (oconfig_item_t *ci) /* {{{ */
75 return (0);
76 } /* }}} int cx_config */
78 +static int cx_init (void) /* {{{ */
79 +{
80 + /* Call this while collectd is still single-threaded to avoid
81 + * initialization issues in libgcrypt. */
82 + curl_global_init (CURL_GLOBAL_SSL);
83 + return (0);
84 +} /* }}} int cx_init */
85 +
86 void module_register (void)
87 {
88 plugin_register_complex_config ("curl_xml", cx_config);
89 + plugin_register_init ("curl_xml", cx_init);
90 } /* void module_register */
92 /* vim: set sw=2 sts=2 et fdm=marker : */
93 diff a/src/write_http.c b/src/write_http.c
94 --- a/src/write_http.c
95 +++ b/src/write_http.c
96 @@ -590,9 +590,18 @@ static int wh_config (oconfig_item_t *ci) /* {{{ */
97 return (0);
98 } /* }}} int wh_config */
100 +static int wh_init (void) /* {{{ */
101 +{
102 + /* Call this while collectd is still single-threaded to avoid
103 + * initialization issues in libgcrypt. */
104 + curl_global_init (CURL_GLOBAL_SSL);
105 + return (0);
106 +} /* }}} int wh_init */
107 +
108 void module_register (void) /* {{{ */
109 {
110 plugin_register_complex_config ("write_http", wh_config);
111 + plugin_register_init ("write_http", wh_init);
112 } /* }}} void module_register */
114 /* vim: set fdm=marker sw=8 ts=8 tw=78 et : */