Skip to content

Commit

Permalink
Dup FDs on startup rather than closing them later
Browse files Browse the repository at this point in the history
Together with the previous commits this does fix #3823
  • Loading branch information
Keno committed Jul 31, 2013
1 parent 93578d7 commit 57ad9b5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 0 additions & 5 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,6 @@ for (x,writable,unix_fd,c_symbol) in ((:STDIN,false,0,:jl_uv_stdin),(:STDOUT,tru
@eval begin
function ($f)(handle::AsyncStream)
global $x
# We're about to dup the file descriptor over, so there's nothing else we can do
# Windows is different since the UV Stream has a handle not a file descriptor
@unix_only if isa($x,AsyncStream) && _fd($x) == RawFD($unix_fd)
ccall(:jl_forceclose_uv,Void,(Ptr{Void},),($x).handle)
end
@windows? ccall(:SetStdHandle,stdcall,Int32,(Uint32,Ptr{Void}),$(-10-unix_fd),_fd(handle).handle) : dup(_fd(handle), RawFD($unix_fd))
unsafe_store!(cglobal($(Expr(:quote,c_symbol)),Ptr{Void}),handle.handle)
$x = handle
Expand Down
7 changes: 7 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,13 @@ void *init_stdio_handle(uv_file fd,int readable)
void *handle;
uv_handle_type type = uv_guess_handle(fd);
jl_uv_file_t *file;
#ifndef _OS_WINDOWS_
// Duplicate the file descritor so we can later dup it over if we want to redirect
// STDIO without having to worry about closing the associated libuv object.
// On windows however, libuv objects remember streams by their HANDLE, so this is
// unnessecary.
fd = dup(fd);
#endif
//printf("%d: %d -- %d\n", fd, type);
switch(type)
{
Expand Down

0 comments on commit 57ad9b5

Please sign in to comment.