This is the mail archive of the cygwin-developers@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

close-on-exec handles are left open by exec parent


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]