BUG: FIFO (named pipe) is broken on Cygwin

Zach Saw zach.saw@gmail.com
Tue Jan 22 03:38:00 GMT 2013


According to POSIX, FIFO allows multiple readers / writers. However, it appears 
that Cygwin's implementation only allows for multiple readers and single writer.

The following code fails on Cygwin but passes on Linux (tested on Ubuntu and 
Debian). Note that this code is to replicate an issue of a bigger project that 
relies on FIFO for interprocess synchronizations.

#include <unistd.h>
#include <fcntl.h>
#include <cerrno>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>

int main()
{
    std::string n = "/tmp/test";
    int err;
    err = mkfifo(n.c_str(), 0666);
    if (err == -1)
    {
        std::cout << "mkfifo error" << std::endl;
        return 0;
    }

    int pipefd[4];
    pipefd[0] = open(n.c_str(), O_RDONLY | O_NONBLOCK);
    if (pipefd[0] == -1)
    {
        std::cout << "open 1 error" << std::endl;
        return 0;
    }
    pipefd[1] = open(n.c_str(), O_WRONLY | O_NONBLOCK);
    if (pipefd[1] == -1)
    {
        std::cout << "open 2 error" << std::endl;
        return 0;
    }
    pipefd[2] = open(n.c_str(), O_RDONLY | O_NONBLOCK); // fails - ENXIO
    if (pipefd[2] == -1)
    {
        std::cout << "open 3 error" << std::endl;
        return 0;
    }
    pipefd[3] = open(n.c_str(), O_WRONLY | O_NONBLOCK); // fails - ENXIO
    if (pipefd[3] == -1)
    {
        std::cout << "open 4 error" << std::endl;
        return 0;
    }

    for (int i=0; i<4; i++)
        close(pipefd[i]);

    unlink(n.c_str());

    return 0;
}


Expected output (as tested on Ubuntu and Debian):
(nil)

Actual output:
open 3 error



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list