Hello.

The following program demonstrates the bug:

import GHC.Handle
import GHC.IOBase
import GHC.Conc
import IO

main = do
   h <- openFile "/tmp/out" WriteMode
   hDuplicateTo h stdout
   
   fdh <- getfd h
   fdstdout <- getfd stdout
   hPutStrLn stderr ("h: " ++ show fdh ++ "\nstdout: " ++ show fdstdout)

   hClose h
   putStrLn "bla"


getfd h@(FileHandle _ mvar) = do
   h__ <- takeMVar mvar
   let fd = fromIntegral (haFD h__)
   putMVar mvar h__
   return fd


The output:

h: 1
stdout: 1
dup: <stdout>: hPutChar: invalid argument (Bad file descriptor)


After hDuplicateTo, both handles use the same file descriptor. Closing one of 
them invalidates the file descriptor underneath the other.

The documentation isn't completely clear about what hDuplicateTo is supposed 
to do. But from the name and the comment in base/GHC/Handle.hs I conclude 
that it should make two handles which use two different fds which refer to 
the same file, like dup2 does.


Bye,
V.W.
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to