Code

patches: Added bts770683_curl_init.
[pkg-collectd.git] / debian / patches / bts770683_curl_init.dpatch
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 @@ -702,9 +702,18 @@ static int apache_read_host (user_data_t *user_data) /* {{{ */
20         return (0);
21  } /* }}} int apache_read_host */
22  
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 */
36  
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 @@ -566,6 +566,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 */
48  
49 diff --git a/src/curl_json.c b/src/curl_json.c
50 index 24e1df1..0948962 100644
51 --- a/src/curl_json.c
52 +++ b/src/curl_json.c
53 @@ -882,9 +882,18 @@ static int cj_read (user_data_t *ud) /* {{{ */
54    return cj_curl_perform (db, db->curl);
55  } /* }}} int cj_read */
56  
57 +static int cj_init (void) /* {{{ */
58 +{
59 +  /* Call this while collectd is still single-threaded to avoid
60 +   * initialization issues in libgcrypt. */
61 +  curl_global_init (CURL_GLOBAL_SSL);
62 +  return (0);
63 +} /* }}} int cj_init */
64 +
65  void module_register (void)
66  {
67    plugin_register_complex_config ("curl_json", cj_config);
68 +  plugin_register_init ("curl_json", cj_init);
69  } /* void module_register */
70  
71  /* vim: set sw=2 sts=2 et fdm=marker : */
72 diff --git a/src/curl_xml.c b/src/curl_xml.c
73 index b941f02..e31e73d 100644
74 --- a/src/curl_xml.c
75 +++ b/src/curl_xml.c
76 @@ -926,9 +926,18 @@ static int cx_config (oconfig_item_t *ci) /* {{{ */
77    return (0);
78  } /* }}} int cx_config */
79  
80 +static int cx_init (void) /* {{{ */
81 +{
82 +  /* Call this while collectd is still single-threaded to avoid
83 +   * initialization issues in libgcrypt. */
84 +  curl_global_init (CURL_GLOBAL_SSL);
85 +  return (0);
86 +} /* }}} int cx_init */
87 +
88  void module_register (void)
89  {
90    plugin_register_complex_config ("curl_xml", cx_config);
91 +  plugin_register_init ("curl_xml", cx_init);
92  } /* void module_register */
93  
94  /* vim: set sw=2 sts=2 et fdm=marker : */
95 diff --git a/src/write_http.c b/src/write_http.c
96 index 62c73b0..04c637b 100644
97 --- a/src/write_http.c
98 +++ b/src/write_http.c
99 @@ -656,9 +656,18 @@ static int wh_config (oconfig_item_t *ci) /* {{{ */
100          return (0);
101  } /* }}} int wh_config */
102  
103 +static int wh_init (void) /* {{{ */
104 +{
105 +  /* Call this while collectd is still single-threaded to avoid
106 +   * initialization issues in libgcrypt. */
107 +  curl_global_init (CURL_GLOBAL_SSL);
108 +  return (0);
109 +} /* }}} int wh_init */
111  void module_register (void) /* {{{ */
112  {
113          plugin_register_complex_config ("write_http", wh_config);
114 +        plugin_register_init ("write_http", wh_init);
115  } /* }}} void module_register */
116  
117  /* vim: set fdm=marker sw=8 ts=8 tw=78 et : */