Help on Windows pipe processing

"Nguyen Thai Ngoc Duy" <[email protected]>
Newsgroups gmane.comp.gnu.make.windows
Message-ID <[email protected]>
Hi,

Let me introduce a bit. I'm working on porting busybox's ash shell to
Windows as part of an attempt to bring Git to Windows without MSYS or
Cygwin dependency. I knew from Git mailing list you guys were Windows
FLOSS experts. So please help this poor FLOSS developer :-)

I concern about Windows pipe behavior. I make a pipe to connect two
programs together. The first program feeds the second  one. Things
worked fine until I found that if the second one dies soon, the first
one won't notice and keep feeding the pipe until it blocks itself.

I attach three programs to demonstrate that. a.c is the feeder. b.c is
the consumer (it actually does not consume anything, just dies out).
c.c is the one that connects a and b together.  You run c.exe, then
look at file "o" or process list. In a perfect world, a.exe should
exit and we should get 999 in "o".

Did I make anything wrong?
-- 
Duy

_______________________________________________
Make-w32 mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/make-w32
a.c (text/x-csrc, 261 B)
#include <stdio.h>

int main(int argc,char **argv)
{
	int i;
	FILE *fp = fopen("o", "w");
	fprintf(fp, "%08x %08x\n", (int)_get_osfhandle(0),(int)_get_osfhandle(1));
	for (i = 0;i < 1000;i ++) {
		printf("%010d\n",i);
		fprintf(fp,"%d\n",i);
		fflush(fp);
	}
}
b.c (text/x-csrc, 170 B)
#include <stdio.h>

int main(int argc,char**argv)
{
	FILE *fp = fopen("o2","w");
	fprintf(fp, "%08x %08x\n", (int)_get_osfhandle(0),(int)_get_osfhandle(1));
	close(0);
}
c.c (text/x-csrc, 366 B)
#include <windows.h>
#include <stdio.h>
#include <process.h>

int main(int argc,char **argv)
{
	int fd;
	int pip[2];
	_pipe(pip, 0, 0);

	fd = dup(1);
	dup2(pip[1], 1);
	spawnl(_P_NOWAIT, "a.exe", "a.exe", NULL);
	close(1);
	dup2(fd, 1);
	close(fd);

	fd = dup(0);
	dup2(pip[0], 0);
	spawnl(_P_NOWAIT, "b.exe", "b.exe", NULL);
	close(0);
	dup2(fd, 0);
	close(fd);
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.