logo       

Runtime system doesn't notice changed file descriptor status: msg#00004

lang.haskell.glasgow.bugs

Subject: Runtime system doesn't notice changed file descriptor status

Hi

I'm building a program which converts file names from ISO8859-1 to UTF-8. It
calls the recode program to do the actual conversion. This part does the
work:

pfade <- fmap lines getContents

pipe_to (unlines pfade)
(execp "recode" ["-f", "latin1..utf8"]
-|= (do pfade_utf8 <- fmap lines getContents --XX error here
mapM_ (\(pfad, pfad_utf8) -> do
...
)
(zip pfade pfade_utf8)
)
)

pipe_to and (-|=) fork two processes, connected through a pipe. I get this
error at the marked point:

In child process, part of a pipe:
IO-Error
Error type: illegal operation
Location: hGetContents
Description: handle is closed
File name: "<stdin>"

The problem is, the call of getContents at the beginning closes the main
process' standard input. It is replaced in the child with the pipe from
recode, but the runtime system doesn't notice that stdin is open again. The
openness state seems to be duplicated in stdin's file handle.

It works when replacing the marked line with the following.

h <- fdToHandle 0 -- from hslibs
pfade_utf8 <- fmap lines (hGetContents h)

I'm using only functions from the System.Posix library (e.g. dupTo), so I
think the runtime system should notice.

Apart from that, is there any way to notify the runtime system that the file
descriptor 0 has changed?

But in the first place, it should be avoided to duplicate the file
descriptor's state in the handle, if possible.

I'm running Linux and GHC 6.2.2.

Greetings,
V.W.

--
http://www.volker-wysk.de


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise