Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

also redirect JL_STDERR etc. when redirecting to devnull #55958

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,14 @@ function _redirect_io_libc(stream, unix_fd::Int)
dup(posix_fd, RawFD(unix_fd))
nothing
end
function _redirect_io_cglobal(handle::Union{LibuvStream, IOStream}, unix_fd::Int)
c_sym = unix_fd == 0 ? cglobal(:jl_uv_stdin, Ptr{Cvoid}) :
unix_fd == 1 ? cglobal(:jl_uv_stdout, Ptr{Cvoid}) :
unix_fd == 2 ? cglobal(:jl_uv_stderr, Ptr{Cvoid}) :
C_NULL
c_sym == C_NULL || unsafe_store!(c_sym, handle.handle)
nothing
end
function _redirect_io_global(io, unix_fd::Int)
unix_fd == 0 && (global stdin = io)
unix_fd == 1 && (global stdout = io)
Expand All @@ -1252,18 +1260,15 @@ function _redirect_io_global(io, unix_fd::Int)
end
function (f::RedirectStdStream)(handle::Union{LibuvStream, IOStream})
_redirect_io_libc(handle, f.unix_fd)
c_sym = f.unix_fd == 0 ? cglobal(:jl_uv_stdin, Ptr{Cvoid}) :
f.unix_fd == 1 ? cglobal(:jl_uv_stdout, Ptr{Cvoid}) :
f.unix_fd == 2 ? cglobal(:jl_uv_stderr, Ptr{Cvoid}) :
C_NULL
c_sym == C_NULL || unsafe_store!(c_sym, handle.handle)
_redirect_io_cglobal(handle, f.unix_fd)
_redirect_io_global(handle, f.unix_fd)
return handle
end
function (f::RedirectStdStream)(::DevNull)
nulldev = @static Sys.iswindows() ? "NUL" : "/dev/null"
handle = open(nulldev, write=f.writable)
_redirect_io_libc(handle, f.unix_fd)
_redirect_io_cglobal(handle, f.unix_fd)
close(handle) # handle has been dup'ed in _redirect_io_libc
_redirect_io_global(devnull, f.unix_fd)
return devnull
Expand Down