| delorie.com/archives/browse.cgi | search |
| Mailing-List: | contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm |
| List-Subscribe: | <mailto:cygwin-subscribe AT sources DOT redhat DOT com> |
| List-Archive: | <http://sources.redhat.com/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT sources DOT redhat DOT com> |
| List-Help: | <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs> |
| Sender: | cygwin-owner AT sources DOT redhat DOT com |
| Delivered-To: | mailing list cygwin AT sources DOT redhat DOT com |
| X-Authentication-Warning: | vivaldi.cpe.ku.ac.th: ans owned process doing -bs |
| Date: | Mon, 22 Jan 2001 00:10:58 +0700 (ICT) |
| From: | Anon Sricharoenchai <ans AT beethoven DOT cpe DOT ku DOT ac DOT th> |
| X-Sender: | ans AT vivaldi DOT cpe DOT ku DOT ac DOT th |
| To: | cygwin AT cygwin DOT com |
| Subject: | Bug when reading from a non-blocking pipe file descriptor, while |
| the opposite end (the writing pipe file descriptor) is closed. | |
| Message-ID: | <Pine.LNX.4.21.0101212338330.27606-100000@vivaldi.cpe.ku.ac.th> |
| MIME-Version: | 1.0 |
The following is the C program to regenerate this bug.
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
void test_func(int n1, int n2) {
int input_from_child[2];
pipe(input_from_child);
if (fork()) {
char buf[20];
close(input_from_child[1]);
fcntl(input_from_child[0], F_SETFL, O_NONBLOCK);
sleep(n1);
printf("%d\n", read(input_from_child[0], buf, sizeof(buf)));
} else {
close(input_from_child[0]);
dup2(input_from_child[1], 1);
close(input_from_child[1]);
sleep(n2);
exit(0);
};
};
int main() {
test_func(1, 0);
test_func(1, 2);
return 0;
};
When compile and run on linux, the output of running this program should
be as follow.
0
-1
But when compile and run using cygwin, the output will be as follow.
-1
-1
The latter case is a bug on cygwin. Because when calling
read(input_from_child[0], buf, sizeof(buf)) from test_func(1, 0), the
file descriptor input_from_child[0] should be in the end of file status
that should cause the read(...) to return 0.
--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |