Skip to content

Commit bcbe9fe

Browse files
also redirect JL_STDERR etc. when redirecting to devnull (#55958)
1 parent b1f53ec commit bcbe9fe

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

base/stream.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,15 @@ function _redirect_io_libc(stream, unix_fd::Int)
12451245
-10 - unix_fd, Libc._get_osfhandle(posix_fd))
12461246
end
12471247
end
1248-
dup(posix_fd, RawFD(unix_fd))
1248+
GC.@preserve stream dup(posix_fd, RawFD(unix_fd))
1249+
nothing
1250+
end
1251+
function _redirect_io_cglobal(handle::Union{LibuvStream, IOStream, Nothing}, unix_fd::Int)
1252+
c_sym = unix_fd == 0 ? cglobal(:jl_uv_stdin, Ptr{Cvoid}) :
1253+
unix_fd == 1 ? cglobal(:jl_uv_stdout, Ptr{Cvoid}) :
1254+
unix_fd == 2 ? cglobal(:jl_uv_stderr, Ptr{Cvoid}) :
1255+
C_NULL
1256+
c_sym == C_NULL || unsafe_store!(c_sym, handle === nothing ? Ptr{Cvoid}(unix_fd) : handle.handle)
12491257
nothing
12501258
end
12511259
function _redirect_io_global(io, unix_fd::Int)
@@ -1256,11 +1264,7 @@ function _redirect_io_global(io, unix_fd::Int)
12561264
end
12571265
function (f::RedirectStdStream)(handle::Union{LibuvStream, IOStream})
12581266
_redirect_io_libc(handle, f.unix_fd)
1259-
c_sym = f.unix_fd == 0 ? cglobal(:jl_uv_stdin, Ptr{Cvoid}) :
1260-
f.unix_fd == 1 ? cglobal(:jl_uv_stdout, Ptr{Cvoid}) :
1261-
f.unix_fd == 2 ? cglobal(:jl_uv_stderr, Ptr{Cvoid}) :
1262-
C_NULL
1263-
c_sym == C_NULL || unsafe_store!(c_sym, handle.handle)
1267+
_redirect_io_cglobal(handle, f.unix_fd)
12641268
_redirect_io_global(handle, f.unix_fd)
12651269
return handle
12661270
end
@@ -1269,6 +1273,7 @@ function (f::RedirectStdStream)(::DevNull)
12691273
handle = open(nulldev, write=f.writable)
12701274
_redirect_io_libc(handle, f.unix_fd)
12711275
close(handle) # handle has been dup'ed in _redirect_io_libc
1276+
_redirect_io_cglobal(nothing, f.unix_fd)
12721277
_redirect_io_global(devnull, f.unix_fd)
12731278
return devnull
12741279
end

0 commit comments

Comments
 (0)