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>
This commit is contained in:
Nelson Billing 2020-02-21 15:54:49 -08:00
parent a4c536dc2d
commit 815497495e

View file

@ -173,7 +173,19 @@ bool LibcurlWrapper::SendSimplePostRequest(const string& url,
} }
bool LibcurlWrapper::Init() { 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_) { if (!curl_lib_) {
curl_lib_ = dlopen("libcurl.so.4", RTLD_NOW); curl_lib_ = dlopen("libcurl.so.4", RTLD_NOW);
} }