]> xenbits.xensource.com Git - libvirt.git/commitdiff
Call curl_global_init from virInitialize to avoid thread-safety issues
authorMatthias Bolte <matthias.bolte@googlemail.com>
Sat, 6 Oct 2012 18:09:20 +0000 (20:09 +0200)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Mon, 8 Oct 2012 19:27:58 +0000 (21:27 +0200)
curl_global_init is not thread-safe. curl_easy_init might call
curl_global_init when it was no called before. But curl_easy_init
can be called from different threads by the ESX driver. Therefore,
call curl_global_init from virInitialize to stop curl_easy_init from
calling it.

Reported by Benjamin Wang.

configure.ac
src/libvirt.c
src/xenapi/xenapi_driver.c

index 767e06cbe33435c0cd8b03986f9440791af24de0..6866d8819b694bb1d9d92e50d17c651a3abb8b85 100644 (file)
@@ -2299,9 +2299,12 @@ dnl
 
 LIBCURL_CFLAGS=""
 LIBCURL_LIBS=""
+have_curl=no
 
 if test "$with_esx" = "yes" || test "$with_esx" = "check" || test "$with_xenapi" = "yes" || test "$with_xenapi" = "check"; then
     PKG_CHECK_MODULES(LIBCURL, libcurl >= $LIBCURL_REQUIRED, [
+        have_curl=yes
+
         if test "$with_esx" = "check"; then
             with_esx=yes
         fi
@@ -2326,6 +2329,11 @@ if test "$with_esx" = "yes" || test "$with_esx" = "check" || test "$with_xenapi"
     ])
 fi
 
+if test "$have_curl" = "yes" ; then
+    AC_DEFINE_UNQUOTED([HAVE_LIBCURL], 1, [whether libcurl is available])
+fi
+AM_CONDITIONAL([HAVE_LIBCURL], [test "$have_curl" = "yes"])
+
 
 if test "$with_esx" = "yes" ; then
     AC_DEFINE_UNQUOTED([WITH_ESX], 1, [whether ESX driver is enabled])
@@ -3081,7 +3089,7 @@ AC_MSG_NOTICE([Libraries])
 AC_MSG_NOTICE([])
 AC_MSG_NOTICE([  libxml: $LIBXML_CFLAGS $LIBXML_LIBS])
 AC_MSG_NOTICE([  dlopen: $DLOPEN_LIBS])
-if test "$with_esx" = "yes" ; then
+if test "$have_curl" = "yes" ; then
 AC_MSG_NOTICE([ libcurl: $LIBCURL_CFLAGS $LIBCURL_LIBS])
 else
 AC_MSG_NOTICE([ libcurl: no])
index ada9a86cde4085472eb35fc30005d9a388b4deb2..76e440163aa1cd024619fb56d9931794ac355bd4 100644 (file)
 # include <winsock2.h>
 #endif
 
+#ifdef HAVE_LIBCURL
+# include <curl/curl.h>
+#endif
+
 #include "virterror_internal.h"
 #include "logging.h"
 #include "datatypes.h"
@@ -418,6 +422,10 @@ virInitialize(void)
 
     virNetTLSInit();
 
+#if HAVE_LIBCURL
+    curl_global_init(CURL_GLOBAL_DEFAULT);
+#endif
+
     VIR_DEBUG("register drivers");
 
 #if HAVE_WINSOCK2_H
index 2fac56123c33842517e695e231e764b595096e3a..d60ad23a3bd2eccf431c8dfcacd8451d21da02b5 100644 (file)
@@ -171,7 +171,6 @@ xenapiOpen (virConnectPtr conn, virConnectAuthPtr auth,
     xmlInitParser();
     xmlKeepBlanksDefault(0);
     xen_init();
-    curl_global_init(CURL_GLOBAL_ALL);
 
     privP->session = xen_session_login_with_password(call_func, privP, username,
                                                      password, xen_api_latest_version);