logo       

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

lang.haskell.glasgow.bugs

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

Hello

I made an error when simplifying the program for the bug report. Here's the
message again.

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 (contents "-")

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

...

lazy_contents :: String -> IO (String, Handle)
lazy_contents pfad = do
h <- if pfad == "-" then return stdin else openFile pfad ReadMode
txt <- hGetContents h
return (txt, h)

contents :: String -> IO String
contents pfad = do
(txt, h) <- lazy_contents pfad
seq (length txt) (return ())
hClose h
return txt


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 contents "-" at the beginning closes the main
process' standard input (mere getContents would semi-close it, same problem).
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 the file handle.

It works when replacing the marked line with the following.

h <- fdToHandle 0
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