Make LibcurlWrapper support static linking.
- Didn't used to support statically linked libcurl, now it does (like
HttpUpload does).
Change-Id: Ic014548225b129f0c1c9ffe6a671f5bd2352b6e6
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/2068947
Reviewed-by: Ivan Penkov <ivanpe@chromium.org>
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
diff --git a/src/common/linux/libcurl_wrapper.cc b/src/common/linux/libcurl_wrapper.cc
index d935174..e96c203 100644
--- a/src/common/linux/libcurl_wrapper.cc
+++ b/src/common/linux/libcurl_wrapper.cc
@@ -173,7 +173,19 @@
}
bool LibcurlWrapper::Init() {
- curl_lib_ = dlopen("libcurl.so", RTLD_NOW);
+ // First check to see if libcurl was statically linked:
+ curl_lib_ = dlopen(nullptr, RTLD_NOW);
+ if (curl_lib_ &&
+ (!dlsym(curl_lib_, "curl_easy_init") ||
+ !dlsym(curl_lib_, "curl_easy_setopt"))) {
+ // Not statically linked, try again below.
+ dlerror(); // Clear dlerror before attempting to open libraries.
+ dlclose(curl_lib_);
+ curl_lib_ = nullptr;
+ }
+ if (!curl_lib_) {
+ curl_lib_ = dlopen("libcurl.so", RTLD_NOW);
+ }
if (!curl_lib_) {
curl_lib_ = dlopen("libcurl.so.4", RTLD_NOW);
}