Skip to content

Commit

Permalink
download(): Clear libpath environment variables before invoking curl
Browse files Browse the repository at this point in the history
We generally don't have a problem when invoking external executables,
however occasionally we are doing something such as running `rr`, which
needs `libgcc_s` from the Julia CSL distribution, and the only way to
get `libgcc_s` for `rr` is to tack its location on to the end of
`LD_LIBRARY_PATH`.  This causes all other executables to search that
directory as well, and right now, that directory is Julia's entire
private libdir, which includes many things such as `libcurl.so`.  This
breaks a system-provided `curl`.

This wil be fixed by JLL stdlib bundling, as we will have much more
fine-grained control over which libraries are added to the paths for
which executables, however in the meantime, an easy fix is to isolate
the system `curl` from our libraries by removing the libpath environment
variables before invoking it.
  • Loading branch information
staticfloat committed May 7, 2020
1 parent f69f64c commit 2058749
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions base/download.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,21 @@ function find_curl()
end
end

# Clear libpath for invoking system executables that we generally don't want to be confused
# by things like a libcurl that sits in Julia's private libdir.
function clear_libpath(f::Function)
withenv(f,
"LD_LIBRARY_PATH" => nothing,
"DYLD_FALLBACK_LIBRARY_PATH" => nothing,
"DYLD_LIBRARY_PATH" => nothing,
)
end

function download_curl(curl_exe::AbstractString, url::AbstractString, filename::AbstractString)
err = PipeBuffer()
process = run(pipeline(`$curl_exe -s -S -g -L -f -o $filename $url`, stderr=err), wait=false)
success = clear_libpath() do
run(pipeline(`$curl_exe -s -S -g -L -f -o $filename $url`, stderr=err), wait=false)
end
if !success(process)
error_msg = readline(err)
@error "Download failed: $error_msg"
Expand All @@ -64,14 +76,18 @@ function download(url::AbstractString, filename::AbstractString)
return download_powershell(url, filename)
elseif Sys.which("wget") !== nothing
try
run(`wget -O $filename $url`)
clear_libpath() do
run(`wget -O $filename $url`)
end
catch
rm(filename, force=true) # wget always creates a file
rethrow()
end
elseif Sys.which("busybox") !== nothing
try
run(`busybox wget -O $filename $url`)
clear_libpath() do
run(`busybox wget -O $filename $url`)
end
catch
rm(filename, force=true) # wget always creates a file
rethrow()
Expand Down

0 comments on commit 2058749

Please sign in to comment.