Subject: Oops! Here's the test case...

From: Pavel Curtis <[email-masked]>
Date: Fri, 21 Aug 1992 14:01:29 -0700

I forgot to enclose the System V test program.  Here it is.

	Pavel/Haakon

--- Begin foo.c ---
#include <sys/types.h>
#include <poll.h>
#include <sys/stat.h>
#include <fcntl.h>

main()
{
    int	rfd, wfd, i;
    struct pollfd fds[1];

    unlink("/tmp/pavel");
    if (mknod("/tmp/pavel", 0666 | S_IFIFO, 0) < 0) {
	perror("Making the FIFO");
	exit(-1);
    } else if ((rfd = open("/tmp/pavel", O_RDONLY | O_NDELAY)) < 0) {
	perror("Opening the FIFO for reading");
	exit(-1);
    } else if ((wfd = open("/tmp/pavel", O_WRONLY)) < 0) {
	perror("Opening the FIFO for writing");
	exit(-1);
    }

    if (fork() == 0) {
	close(rfd);
	sleep(2);
	exit(0);
    }

    close(wfd);

    fds[0].fd = rfd;
    fds[0].events = POLLIN;

    if ((i = poll(fds, 1, 10000)) < 0) {
	perror("Polling");
	exit(-1);
    }

    printf("Polling succeeded with result %d and flags:", i);
    if (fds[0].revents & POLLIN)
	printf(" POLLIN");
    if (fds[0].revents & POLLOUT)
	printf(" POLLOUT");
    if (fds[0].revents & POLLPRI)
	printf(" POLLPRI");
    if (fds[0].revents & POLLERR)
	printf(" POLLERR");
    if (fds[0].revents & POLLHUP)
	printf(" POLLHUP");
    if (fds[0].revents & POLLNVAL)
	printf(" POLLNVAL");

    printf("\n");

    exit(0);
}
--- End foo.c ---