Hi everyone,

I am using select(2) on a FIFO fd and monitoring
for readability.  select(2) doesn't return after the writer
exits.

The same piece of code marks the fd as readable on Linux.
Not sure which behaviour is correct though.

Doing a very similar test with stdin and closing it before
the call to select(2) behaves as expected and marks the fd
as readable.

I wrote the following PoC to demonstrate this.

Any ideas?

Thanks,
Dimitris

#include <sys/select.h>
#include <sys/stat.h>

#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

#define FIFONAME "testfifo"

int
main(void)
{
        int r;
        int fd;
        fd_set rfds;

        r = mkfifo(FIFONAME, 0666);
        if (r < 0 && errno != EEXIST)
                err(1, "mkfifo: %s", FIFONAME);
        fd = open(FIFONAME, O_RDONLY | O_NONBLOCK);
        if (fd < 0)
                err(1, "open: %s", FIFONAME);
        FD_ZERO(&rfds);
        FD_SET(fd, &rfds);
        printf("Now run cat > %s and ^D\n", FIFONAME);
again:
        r = select(fd + 1, &rfds, NULL, NULL, NULL);
        if (r < 0) {
                if (errno == EINTR)
                        goto again;
                err(1, "select");
        }
        if (FD_ISSET(fd, &rfds))
                printf("fd is readable\n");
        close(fd);
        unlink(FIFONAME);
        return 0;
}

Reply via email to