X-Recipient: archive-cygwin AT delorie DOT 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:reply-to :references:mime-version:content-type:in-reply-to; q=dns; s= default; b=D/UilUprZp7Gn6mGtCNRkM80v2/G2hrO5imDZNCWpGfYcQKpW3Xi1 hQaVj6jESdOMZ+qdD3zW3v0R7ZuHHv+sRtm7JcfMJNbFrktHJDRUe7DrsHmqg1An 9U+W3U7kBxv/Kkzj3dpxEFePnRSDCRGRs6rjAMFLGij5D0UijDoec0= 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:reply-to :references:mime-version:content-type:in-reply-to; s=default; bh=+TOzfoXEOFt2tCK+UOv+c+CU4WA=; b=TdaBcnhBR7C80xNdWKj1K7hwkoIi n+WmzLm76uMg7b5WjQVSYYsmZVnyVS54AYS+ecOwj3Wl5Ic+GcNtELZ1XJuHHV4i pO28oaUtnWWyNtjWy86Gn1IPQpL7rg8WlM0MTJvX5O/ceXxzPMe+vjtEyxzxHf0X 141m3EnsgvcYUgA= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.9 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: calimero.vinschen.de Date: Thu, 5 Mar 2015 14:58:39 +0100 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: PTY dies when master in parent process is closed. Message-ID: <20150305135839.GZ3213@calimero.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <20150305215323 DOT 760df4752fdbd6f19a931851 AT nifty DOT ne DOT jp> <20150305133100 DOT GY3213 AT calimero DOT vinschen DOT de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="SUcp5/vPb8ZOOFiR" Content-Disposition: inline In-Reply-To: <20150305133100.GY3213@calimero.vinschen.de> User-Agent: Mutt/1.5.23 (2014-03-12) --SUcp5/vPb8ZOOFiR Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mar 5 14:31, Corinna Vinschen wrote: > Hi Takashi, >=20 > On Mar 5 21:53, Takashi Yano wrote: > > Package: cygwin > > Version: 1.7.35-1 > >=20 > > PTY of cygwin dies when master fd in parent process > > is closed while a child process keeps valid master fd. > >=20 > > To reproduce this problem: > > 1) Compile following C sources (Test Case 1, 2) > > 2) Execute them. > >=20 > > Expected results are both: > > 01234567890 > >=20 > > However, result of Test Case 2 is: > > Hungup > > while Test Case 1 is as expected. > >=20 > > Difference between Test Case 1 and Test Case 2 is > > which process is worked in parent. In other words, > > master is in parent process in Test Case 1, while > > master is in child process in Test Case 2. > >=20 > > I looked into cygwin source code, and found the cause. > > fhandler_pty_master::close() calls get_ttyp()->set_master_closed() > > if it is called from the process which opend the master. > > It is regardless whether other processes have the valid > > master handle. > >=20 > > get_ttyp()->set_master_closed() should be called only > > when the last valid master handle among all processes > > is closed. >=20 > No, I don't think so. The name of the method, set_master_closed() is > probably a bit misleading, as is the name of the test method > is_master_closed(). What it really means is this: >=20 > The process creating the pty will start a master control thread (MCT). > This thread is used for duplicating handles from the slave side, if the > slave has no permissions to duplicate the from_master/to_master handles > by itself. The tty member master_pid points to the process running the > MCT. >=20 > If the master fd is closed in the process having created the master, the > MCT is stopped as well. set_master_closed() sets master_pid to -1 to > reflect the fact that no MCT is running anymore. So, calling > set_master_closed() from close is not wrong, AFAICS. >=20 > What's wrong is to test for is_master_closed() in fhandler_pty_slave::rea= d, > and to generate SIGHUP in case the MCT isn't running. I think this code > snippet was a thinko, perhaps induced by the misleading name of the metho= d. >=20 > While looking through the code, I think that the second usage of > is_master_closed() (in fhandler_pty_slave::open()) is just as wrong... I applied a patch. Please have a look. Thanks. Corinna --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --SUcp5/vPb8ZOOFiR Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBAgAGBQJU+GEPAAoJEPU2Bp2uRE+gIOMP/ivTKZEFUd1shPKWE5sxszeO aQgo93EXra5eled0o4v6570VDqis+lI+4riEB+e8MfOaPQgbFe62vHBTCgG6+5y/ Ch53OiB7rwceO7EoJD3jeULKSLcLwTw17wGd5KAPBYAH0QUDwJ9fJJdlIvg/P3nn G3a77wWO2LQhoniMho3B+o8K7aYkDvB7X4bElY7rnLlahbmzms4TCdfLm20K8iRs DKcXSFYM7uM1QpPO+xmtRbnIoLpfdvR/q/cnp8/d3kkHs9o8gKY9sKa/DQw5IEig 5iu5654tLTvNefBAXnFdOEz7h9HZFAXclDI+i05iY8bXDBw9riiMVyGwOc+b5DeU O2Oydeme8mBjuj11tJaW324bRcZ1RATWEHNO1Jt9i+sFQQ/zU2ckL0ikQo7v//D6 TRLYuxNfLORRkR1Dn5Zp2TaAcNBEOceYY0bqsApTZflZo6W/KuMjK+uLI98X+ohX Ok62WjeiTtyTII8JXsJFRZ+HUp+rn8ydZK/s3RQAX8bkLgoaPUKaWCuD8iYOIVsd ydYgs9voT30aevOf4+tKuvkIdYBT01ivwZygKiIGEgDldVQ0KFW1jVrvQU81Kec9 AfT8qIL6uo2G/++e/RmbSlUwfW7p3tief/bqhEolKZYz9HJ50b5MZv7MBXXoocpe TzE4+wz2hA9/nHA1OLdM =0HjV -----END PGP SIGNATURE----- --SUcp5/vPb8ZOOFiR--