X-Recipient: archive-cygwin@delorie.com
X-SWARE-Spam-Status: No, hits=0.0 required=5.0 	tests=BAYES_50
X-Spam-Check-By: sourceware.org
Date: Tue, 22 Dec 2009 23:43:09 +0100
From: Enrico Forestieri <forenr@lyx.org>
To: cygwin@cygwin.com
Subject: select() and named pipes
Message-ID: <20091222224309.GA3504@GIOVE>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="dDRMvlgZJXvWKvBx"
Content-Disposition: inline
User-Agent: Mutt/1.4.2.2i
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

--dDRMvlgZJXvWKvBx
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

I am experiencing a problem with select() and named pipes in cygwin 1.7.
The attached test case segfaults on the select() call, but works fine
with both cygwin 1.5 and linux.

-- 
Enrico

--dDRMvlgZJXvWKvBx
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="selectbug.c"

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#define FIFONAME "/tmp/pipe"

int main(void)
{
    int fd;
    int nsel;
    fd_set readfds;
    FD_ZERO(&readfds);

    if (mkfifo(FIFONAME, 0600) < 0) {
	perror("mkfifo");
	exit(1);
    }

    fd = open(FIFONAME, O_RDONLY | O_NONBLOCK);

    if (fd < 0) {
	perror("open");
	remove(FIFONAME);
	exit(2);
    }

    FD_SET(fd, &readfds);
    do {
	nsel = select(fd + 1, &readfds, 0, 0, 0);
    } while (nsel == -1 && (errno == EINTR || errno == EAGAIN));

    if (nsel == -1) {
	perror("select");
	exit(3);
    }

    if (FD_ISSET(fd, &readfds)) {
	char buf[100];
	int status;
	while ((status = read(fd, buf, sizeof(buf) - 1))) {
	    if (status > 0) {
		buf[status] = '\0';
		printf("%s", buf);
	    } else {
		printf("\n");
		if (errno != EAGAIN)
		    perror("read");
		break;
	    }
	}
    }

    close(fd);
    remove(FIFONAME);
    return 0;
}


--dDRMvlgZJXvWKvBx
Content-Type: text/plain; charset=us-ascii

--
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
--dDRMvlgZJXvWKvBx--
