This is the mail archive of the
cygwin-developers@cygwin.com
mailing list for the Cygwin project.
close-on-exec handles are left open by exec parent
- To: cygwin-developers at cygwin dot com
- Subject: close-on-exec handles are left open by exec parent
- From: egor duda <deo at logos-m dot ru>
- Date: Tue, 24 Jul 2001 15:46:32 +0400
- Organization: deo
- Reply-To: egor duda <cygwin-developers at cygwin dot com>
Hi!
there was bug reports about "expect> spawn ping" not returning to
expect prompt. Here's the simple testcase and analysis:
#include <unistd.h>
#include <sys/fcntl.h>
int
main (int argc, char** argv)
{
int x[2];
char a;
int ret, pid;
if (pipe (x) < 0)
{
perror ("pipe");
return 1;
}
pid = fork ();
switch (pid)
{
case -1:
perror ("fork"); return 1;
case 0:
close (x[0]); fcntl (x[1], F_SETFD, 1);
execlp ("ping.exe", "ping.exe", "-t", "cygwin.com", NULL);
default:
close (x[1]);
ret = read (x[0], &a, sizeof (a));
if (ret < 0)
{
perror ("read");
return 1;
}
return 0;
}
}
test.exe create pipe and forks. when write end of the pipe is marked
as close-on-exec, we DuplicateHandle () appropriately. but forked
instance left running after execlp () is performed, and it doesn't
close it's own copy of pipe handle. so read () blocks forever.
i can see 2 ways to fix it. We can either always perform
dtable::fixup_before_exec() and close handles marked as close-on-exec
there, or always close all handles when exec child is started and exec
parent cycles waiting for its child to exit.
egor. mailto:deo@logos-m.ru icq 5165414 fidonet 2:5020/496.19