delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/12/22/17:43:39

X-Recipient: archive-cygwin AT delorie DOT 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 AT lyx DOT org>
To: cygwin AT cygwin DOT com
Subject: select() and named pipes
Message-ID: <20091222224309.GA3504@GIOVE>
Mime-Version: 1.0
User-Agent: Mutt/1.4.2.2i
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT 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--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019