From 6d14d9120c1ca06070f50afad9bb728b5f8a74bb Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Tue, 1 Oct 2024 16:35:56 -0400 Subject: [PATCH] also redirect JL_STDERR etc. when redirecting to devnull --- base/stream.jl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/base/stream.jl b/base/stream.jl index 93aeead79eb9ce..2f6d7f4aa45485 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -1244,6 +1244,14 @@ function _redirect_io_libc(stream, unix_fd::Int) dup(posix_fd, RawFD(unix_fd)) nothing end +function _set_cglobal_stdio(f::RedirectStdStream, handle::Union{LibuvStream, IOStream}) + 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) + nothing +end function _redirect_io_global(io, unix_fd::Int) unix_fd == 0 && (global stdin = io) unix_fd == 1 && (global stdout = io) @@ -1252,11 +1260,7 @@ 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(f, handle) _redirect_io_global(handle, f.unix_fd) return handle end @@ -1264,6 +1268,7 @@ 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(f, handle) close(handle) # handle has been dup'ed in _redirect_io_libc _redirect_io_global(devnull, f.unix_fd) return devnull