www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/2001/07/24/07:51:58

Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-developers-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin-developers/>
List-Post: <mailto:cygwin-developers AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-developers-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-developers-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin-developers AT sources DOT redhat DOT com
Date: Tue, 24 Jul 2001 15:46:32 +0400
From: egor duda <deo AT logos-m DOT ru>
X-Mailer: The Bat! (v1.53 RC/4)
Reply-To: egor duda <cygwin-developers AT cygwin DOT com>
Organization: deo
X-Priority: 3 (Normal)
Message-ID: <9715860566.20010724154632@logos-m.ru>
To: cygwin-developers AT cygwin DOT com
Subject: close-on-exec handles are left open by exec parent
MIME-Version: 1.0

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 AT logos-m DOT ru icq 5165414 fidonet 2:5020/496.19

- Raw text -


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