delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2015/03/05/08:31:19

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=tN15Vc1azEx5pUQaU9NcrvNrOLMD8en+lPsSDvICvg2TwZ4IYc9fF
lh34SYcfaxBetWtn6u6Cws7AUpKEdHC/MjKfdGYdX0rjA/5rFiwgFPfJvsZ4UMwb
piMHjCtrp72bdJwW2I0XLbnyCyLUHANbRY55/+hJOgt9jMNQzD84cg=
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=3P4x7kLM/lXpd5YUe2Bb9xdDYyo=; b=oOvOBMpk92kHUvUZ44p9xWdXev0x
BFfvFG+iaRDrGgQLi77I5/z/PjODPmQYobh1coiCGIgxHsXQqZqjEu2HPn0PSQ6q
I6jmVcojCzOq2u6n/Su0vz6ccYTCuBMNIDWyZaf7ThJsTOlZpalI2m+K5ks8qwiz
BZ3i9fl/zJOngzk=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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:31:00 +0100
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: PTY dies when master in parent process is closed.
Message-ID: <20150305133100.GY3213@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>
MIME-Version: 1.0
In-Reply-To: <20150305215323.760df4752fdbd6f19a931851@nifty.ne.jp>
User-Agent: Mutt/1.5.23 (2014-03-12)

--07UuamFNDT4U/3KT
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi Takashi,

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.

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:

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.

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.

What's wrong is to test for is_master_closed() in fhandler_pty_slave::read,
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 method.

While looking through the code, I think that the second usage of
is_master_closed() (in fhandler_pty_slave::open()) is just as wrong...


Corinna

--=20
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

--07UuamFNDT4U/3KT
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBAgAGBQJU+FqUAAoJEPU2Bp2uRE+gIFoQAJJXKvoWd/W8XLl9ahwTQSTZ
lTD6F0ETAc8k+Q++70FKd/DsEG3a4b85DvGkBxP8Nx6q1jg54+SUJwc/D02WKSrY
C8S61e44mzv2/yqFzQWDYkfkf8dynGo1bdcebVZDeEe2Cg6gppLfS1oXLR9VFMn2
XlWjjBpCB8zfi3MziPZ5GNltD5gfuRH5bi5sTyjo0Rj9Bmaz0/nF/nJ2dUQvA6bW
mF38Q7EbDc7IMnMSR/E9xqRo0+kSoNmMfqekUL1WqwUA+phUqzaPktd61ZbFzrEY
19czObS582MzZAg1ABgt+fN5jWriN3bVTbz0hZNBHGJ+1xV9YMOw4ttTrh1SZRDK
54vsSW7+ThdEsC1BuXTtmibq0TBXlOI35oShtj6aaBAjuNbR4r2QxVyx0nkmkuMR
gM4NWrWF/O6P+6p/onKHPs7G8zR6eIfAbUyaFgmI4WPdD3mQ6+5UYA/ijNzHo1PL
XdY6aM0DWgMuLB510sZN8eJWlwEWpelXhNh5qcmwwh/FET/TG0eBWiMdLiZnfWTO
aEUCclndookcN5TB5X+/0FuCs/H00UjaOmRnmSzRH7Ok/r3dm6Yfih9+nVjufu94
3BZrpBpOhKGh28KNm5Z7gvlBlRrsFNNsGqoY6n6l6hDvX/cRCCfPoTFbTIuF0mC6
BlLGqNz6OAhUaUnJvuXf
=98qs
-----END PGP SIGNATURE-----

--07UuamFNDT4U/3KT--

- Raw text -


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