Skip to content

Commit

Permalink
also redirect JL_STDERR etc. when redirecting to devnull
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Oct 2, 2024
1 parent fbb3e11 commit 2ee5fbf
Showing 1 changed file with 10 additions and 5 deletions.
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 _set_cglobal_stdio(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)
_set_cglobal_stdio(handle, f.unix_fd::Int)
_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)
_set_cglobal_stdio(handle, f.unix_d)
close(handle) # handle has been dup'ed in _redirect_io_libc
_redirect_io_global(devnull, f.unix_fd)
return devnull
Expand Down

0 comments on commit 2ee5fbf

Please sign in to comment.