Bug with readFile and named pipes

Thomas Hallgren hallgren at cse.ogi.edu
Wed Aug 22 01:51:49 EDT 2001


Hi.

Programs that read from a named pipe usually block until a writer opens 
the pipe and writes something to it. The following program,

    main = putStr =<< readFile "/tmp/p"

(where "/tmp/p" refers to a named pipe) exhibits this behavour when 
compiled with HBC or when run with runhugs, but *not* when compiled with 
GHC. Instead the program immediately exists, returning the empty string.

Tracing system calls reveals the following:

    ...
    open("/tmp/p", O_RDONLY|O_NONBLOCK|O_NOCTTY) = 3
    ...
    read(3, "", 8192)                       = 0
    close(3)                                = 0
    ...

Apparently, opening the file in nonblocking mode has undesirable effects...

I consider this a bug and hope that it will be fixed for the 5.02 
release. Is there a simple workaround I can use in the mean time?

Regards,
Thomas Hallgren





More information about the Glasgow-haskell-bugs mailing list