[Haskell-cafe] I/O system brokenness with named pipes

Don Stewart dons at galois.com
Fri Apr 11 06:33:53 EDT 2008


jgoerzen:
> So I have a need to write data to a POSIX named pipe (aka FIFO).  Long
> story involving a command that doesn't have an option to read data
> from stdin, but can from a named pipe.
> 
> I have created the named pipe from Haskell no problem.
> 
> But I can't use writeFile to write data to it.  Worse, it returns:
> 
> *** Exception: /tmp/bakroller.zD0xHj/fifo: openFile: does not exist
>     (No such device or address)
> 
> which is completely false, as it *does* exist, and I can cat to it as
> expected.  The call should block until everything is read on the
> remote end.
> 
> I thought maybe writeFile is being weird, so I tried:
> 
> openFile "/tmp/bakroller.zD0xHj/fifo" WriteMode

Hmm, I can get this to work, but only if I have another process waiting
on the pipe already:

                            $ mkfifo /tmp/pipe
    $ tail -f /tmp/pipe     $ ghc -e 'writeFile "/tmp/pipe" "test"'
    testtesttesttest^C

However, if I don't have 'tail' waiting on the pipe, it fails.

> There is no logical reason I can see for this behavior.  In fact,
> something must be going to *extra* effort to avoid writing to a named
> pipe, and I can't work out why.  Named pipes are a standard, useful
> part of a system and shouldn't be ignored like this.
> 
> Interestingly, readFile works fine on a named pipe.
> 
> What's going on here?  Am I going to have to resort to the
> System.Posix interface just to be able to write to a named pipe?

Something fishy.

-- Don


More information about the Haskell-Cafe mailing list