X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:date:from:to:subject:message-id:in-reply-to
	:references:mime-version:content-type:content-transfer-encoding;
	 q=dns; s=default; b=nYtQ+3OW1z4cMmihPxgzDoXPEk4CiskUqtQ1PYojIsN
	21Gimdq7z81doLIBi+qYdeBGPTh07Jz+Wrm+YkaGWBLQuonK5s+d8FhlP3UHH1r7
	tTGxUd4HvYscUF8p6JHYTRSsextr1ipJDJIspSx6VEKu8Eaq6aifD4W5aG3sAaeI
	=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:date:from:to:subject:message-id:in-reply-to
	:references:mime-version:content-type:content-transfer-encoding;
	 s=default; bh=oux/boziD60UmX1JWXc/5qqKOxI=; b=TCHSbVUCpt73WxydS
	egwi+v5w+dCmzTl29CK/ySIbxxTln7vQ7yjf9unM+vBzMt84zuybDYMuASdZ+bqW
	vrFBK0JbQf3Uhr88mIqC0DDk1tXQ9M3mG37ggst91JCR/xvhKFlTYDZ1rRvLFpSx
	Uavbw20qzOTR3bTBTpyG2S51Hw=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_SORBS_DUL,SPF_PASS autolearn=ham version=3.3.2
X-HELO: conuserg003-v.nifty.com
X-Nifty-SrcIP: [121.93.68.199]
Date: Fri, 6 Mar 2015 20:07:10 +0900
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin@cygwin.com
Subject: Re: PTY dies when master in parent process is closed.
Message-Id: <20150306200710.1264a46aa8dd633943e56212@nifty.ne.jp>
In-Reply-To: <20150305135839.GZ3213@calimero.vinschen.de>
References: <20150305215323.760df4752fdbd6f19a931851@nifty.ne.jp>	<20150305133100.GY3213@calimero.vinschen.de>	<20150305135839.GZ3213@calimero.vinschen.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-IsSubscribed: yes

On Thu, 5 Mar 2015 14:58:39 +0100
Corinna Vinschen <corinna-cygwin@cygwin.com> wrote:

> I applied a patch.  Please have a look.

I have tested the latest CVS version, and found
a new problem.

With new CVS version, slave side can not detect
closure of master.

Please use following Test Case 3. Test Case 3 is
not terminated by itself with latest CVS.

It seems that the program is stopping at
cygwait(input_available_event, time_to_wait)
in fhandler_pty_slave::read().

I guess input_available_event should be set when
the last valid master fd is closed.


/***************/
/* Test Case 3 */
/***************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <pty.h>
#include <wait.h>

int main()
{
    int master, slave;
    pid_t pid;

    if ( openpty(&master, &slave, NULL, NULL, NULL) < 0) {
        perror("openpty()");
        exit(EXIT_FAILURE);
    }

    pid = fork();
    if (pid < 0) {
        perror("fork()");
        exit(EXIT_FAILURE);
    }

    if (pid != 0) { /* Parent */
        close(slave);
        write(master, "0123456789\n", 11);
        usleep(100000); /* wait for slave read() */
        close(master);
        wait(NULL);
    } else { /* Child */
        close(master);
        for (;;) {
            char buf[BUFSIZ];
            int len = read(slave, buf, sizeof(buf));
            if (len <= 0) {
                perror("read()");
                break;
            }
            write(STDOUT_FILENO, buf, len);
        }
        close(slave);
    }

    return EXIT_SUCCESS;
}


-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

