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:in-reply-to :references:mime-version:content-type; q=dns; s=default; b=tEnzJ 8NegKzbXrdWfKVOt2X3MTGSsDdt8evCIdRLdd1d4KzVYOuWt/6q8vreBmls9eCnt tacwRHb3xySEK27U5dJoNx0Gk+3EbKy9uunuk//nYBaRoxB833sUKCLOxswXcbAh BOwbxk11eYzJmk3lV2hThW+vvNGFqJxl13jy/4= 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; s=default; bh=/jkqtkj66jK cPocO+4HM+2ULU9E=; b=dbKubt/y8FAhJlFnIWlaVjcG4bL3CpvBVUyaMJrgv+Y T57jU+VPy5Xf+dy7TqFYew7l/FYKpNJnoKclTfl7r5eHFB/EgzQ2fIshCLFfCH/Y eto3yb2V4YO5IFq2fUDgli554DH1/veAJZbJw7xhrMbUmShfCTpikl14rumImpco = 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=-0.6 required=5.0 tests=AWL,BAYES_40,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: Sun, 7 Jun 2015 09:03:29 +0900 From: Takashi Yano To: cygwin AT cygwin DOT com Subject: Re: cygwin-2 process handling (about SIGHUP) Message-Id: <20150607090329.da5f631aabbbe31a5309e526@nifty.ne.jp> In-Reply-To: <20150528141612.GD27014@calimero.vinschen.de> References: <1573487218 DOT 1490468 DOT 1431969356192 DOT JavaMail DOT yahoo AT mail DOT yahoo DOT com> <555B6F71 DOT 4040906 AT cornell DOT edu> <555B7E03 DOT 40404 AT cornell DOT edu> <20150521205357 DOT 2c125b3bcaf877d0843b52b1 AT nifty DOT ne DOT jp> <20150527122312 DOT GF16927 AT calimero DOT vinschen DOT de> <20150527151734 DOT GM16927 AT calimero DOT vinschen DOT de> <20150528114728 DOT GA27014 AT calimero DOT vinschen DOT de> <20150528210932 DOT 3ffc9662998ff7ba9983990a AT nifty DOT ne DOT jp> <20150528214409 DOT 269b5c2bc3eca9dbd888d032 AT nifty DOT ne DOT jp> <20150528141612 DOT GD27014 AT calimero DOT vinschen DOT de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart=_Sun__7_Jun_2015_09_03_29_+0900_uCisFul7s9sLIaAq" X-IsSubscribed: yes --Multipart=_Sun__7_Jun_2015_09_03_29_+0900_uCisFul7s9sLIaAq Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Hi Corinna, On Thu, 28 May 2015 16:16:12 +0200 Corinna Vinschen wrote: > I applied this patch. I'm not comfortable with removing the SIGHUP > handling from slave::read in favor of just setting errno to EIO. > EIO seems wrong here. Not being able to access the pipe anymore > should be equivalent to a hangup. Alternatively the return code > from the Windows function should be checked for ERROR_BROKEN_PIPE, > perhaps, but that introduces some more code, Regarding SIGHUP, I have a different thought. I have checked the behaviour of PTY on other systems than cygwin. However, no system raises SIGHUP on the read()/write() access to PTY, of which the other side is closed. But on the close() in the master side, only when the slave side of the PTY is the controlling terminal, SIGHUP is sent to the slave side. I have tested on Debian GNU/Linux and FreeBSD as well as Cygwin. The test case is as attached (pipe_pty_test.tgz). The testing procedure is as follows. tar xzvf pipe_pty_test.tgz make make test This test case checks how the PTY behaves when the other side of the PYT is closed. As a comparison, behaviour of pipe is also tested. On Debian, the result is: Linux debian 3.16.0-4-686-pae #1 SMP Debian 3.16.7-ckt9-3~deb8u1 (2015-04-24) i686 GNU/Linux === pipe read ========== R: 0 read(): Success === pipe write ========= signal: 13 W: -1 write(): Broken pipe === pty master read ==== MR: -1 read(): Input/output error === pty master write === MW: 11 === pty slave read ===== SR: -1 read(): Input/output error === pty slave write ==== SW: -1 write(): Input/output error === pty master close === signal: 18 signal: 1 usleep(): Interrupted system call On FreeBSD, the result is: FreeBSD FreeBSD-VM 10.1-RELEASE FreeBSD 10.1-RELEASE #0 r274401: Tue Nov 11 22:51:51 UTC 2014 root AT releng1 DOT nyi DOT freebsd DOT org:/usr/obj/usr/src/sys/GENERIC i386 === pipe read ========== R: 0 read(): No error: 0 === pipe write ========= signal: 13 W: -1 write(): Broken pipe === pty master read ==== MR: 0 read(): No error: 0 === pty master write === MW: 11 === pty slave read ===== SR: 0 read(): No error: 0 === pty slave write ==== SW: -1 write(): Device not configured === pty master close === signal: 1 usleep(): Interrupted system call However, on cygwin, the result is: CYGWIN_NT-6.1-WOW Express5800-S70 2.0.3(0.287/5/3) 2015-06-03 13:55 i686 Cygwin === pipe read ========== R: 0 read(): No error === pipe write ========= signal: 13 W: -1 write(): Broken pipe === pty master read ==== MR: -1 read(): Input/output error === pty master write === MW: 11 === pty slave read ===== signal: 1 SR: 0 read(): No error === pty slave write ==== signal: 1 SW: -1 write(): Input/output error === pty master close === usleep(): No error On cygwin, extra SIGHUPs (signal: 1) are generated in the pty- slave-read case and in the pty-slave-write case. On the contrary, SIGHUP is not generated in the pty-master-close case while it is generated on other systems. On the Debian, SIGCONT (signal: 18) is also sent in the pty-master-close case. Although SIGHUP on the master closure was pointed out in the past: https://www.cygwin.com/ml/cygwin/2011-07/msg00328.html, it was not adopted at that time. In the track of Debian/FreeBSD, SIGHUP should not be generated on the read()/write() access on the slave side, but should be generated on the close() on the master side, only when the slave side of the PTY is the controlling terminal. It seems that this behaviour is specified in the POSIX standard. http://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html To make the behaviour match with the test results on other systems, I have made a patch attached (cygwin.patch.20150604). With this patch, everything works nicely for me as well. Furthermore, with this patch, mc (midnight commander) becomes exiting normally. On cygwin 2.0.3-1, mc has a problem which leaves a subshell process on the background. To reproduce this problem, execute env SHELL=/bin/bash mc on cygwin 2.0.3-1, and type 'exit'. You will find bash process remains in background. I have confirmed this problem can be resolved by this patch. For the reason above, I think it is better to make the behaviour match with other systems as well as the POSIX specification. What do you think? ChangeLog is as follows. 2015-06-04 Takashi Yano * fhandler_tty.cc (fhandler_pty_slave::write): Move causing of SIGHUP into fhandler_pty_master::close(). (fhandler_pty_slave::read): Ditto. (fhandler_pty_master::close): Ditto. -- Takashi Yano --Multipart=_Sun__7_Jun_2015_09_03_29_+0900_uCisFul7s9sLIaAq Content-Type: application/x-gtar; name="pipe_pty_test.tgz" Content-Disposition: attachment; filename="pipe_pty_test.tgz" Content-Transfer-Encoding: base64 H4sIAJUscFUAA+1a/2/aRhTPr/ivOLGsMi0Qf4WNhKkaU6VJTTctmaopq5Br n8upxkY+E5pM+d93X3zGQEjpEPaI3kdRbZ/ffe753flz71HPyAyP065/ckAY DD3H4Uez7xriyP5EOz+3befEtFzbMSzX4vdNBvsEGYd0SmFOMy9F6OTOi5On 7N4lMa7Cn4rxHYn9aB5gdEGzgCTdyU/aSlNEPq62zWPCmtfsyKfYi1bbcJrG 63R39GzhkYy3arcJCRDrOJ54cRDhVCdxxq9b2j9aI5yl7DLU2UiMp42acoQB +j74O262hd259qBpvNPUI7EuuvGrMLixPpxrDX/CpvXjPLwxDcvhDfxmirP8 jJxrWoNdoiGasVdAD4MWvxMiXTQOUcdsIUbZmDEHklRvCqtWk1s18BeS6cyA nT8UNGGSftbLJBfIWKWQFo9QqC7MHJ29RL97KWYuvjxjdn6UUO7djfFB9JvT COOZboo3R7QUFqa04BHW3/359q24YqzzNEZG7ipjH01IFAhy5g/SydA4R+SC EbLDq1fSYxlunbTLM6Qed21AMdHs+fkQMhIp9gLpcpvPACe5x0mos/MW77Ex u38UE8uDUA7hcD2GglvG8EFbj45Wel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et-stream; name="cygwin.patch.20150604" Content-Disposition: attachment; filename="cygwin.patch.20150604" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3dpbnN1cC9jeWd3aW4vZmhhbmRsZXJfdHR5LmNjIGIv d2luc3VwL2N5Z3dpbi9maGFuZGxlcl90dHkuY2MKaW5kZXggMWI1YzE4Yi4u ZjIyOTk4ZiAxMDA2NDQKLS0tIGEvd2luc3VwL2N5Z3dpbi9maGFuZGxlcl90 dHkuY2MKKysrIGIvd2luc3VwL2N5Z3dpbi9maGFuZGxlcl90dHkuY2MKQEAg LTYyMiw3ICs2MjIsNiBAQCBmaGFuZGxlcl9wdHlfc2xhdmU6OndyaXRlIChj b25zdCB2b2lkICpwdHIsIHNpemVfdCBsZW4pCiAJZGVmYXVsdDoKIAkgIF9f c2V0ZXJybm9fZnJvbV93aW5fZXJyb3IgKGVycik7CiAJfQotICAgICAgcmFp c2UgKFNJR0hVUCk7CQkvKiBGSVhNRTogU2hvdWxkIHRoaXMgYmUgU0lHVFRP VT8gKi8KICAgICAgIHRvd3JpdGUgPSAtMTsKICAgICB9CiAgIHJldHVybiB0 b3dyaXRlOwpAQCAtNzQ5LDcgKzc0OCwxMiBAQCBmaGFuZGxlcl9wdHlfc2xh dmU6OnJlYWQgKHZvaWQgKnB0ciwgc2l6ZV90JiBsZW4pCiAJICBnb3RvIG91 dDsKIAl9CiAgICAgICBpZiAoIWJ5dGVzX2F2YWlsYWJsZSAoYnl0ZXNfaW5f cGlwZSkpCi0JcmFpc2UgKFNJR0hVUCk7CisJeworCSAgUmVsZWFzZU11dGV4 IChpbnB1dF9tdXRleCk7CisJICBzZXRfZXJybm8gKEVJTyk7CisJICB0b3Rh bHJlYWQgPSAtMTsKKwkgIGdvdG8gb3V0OworCX0KIAogICAgICAgLyogT24g Zmlyc3QgcGVlayBkZXRlcm1pbmUgbm8uIG9mIGJ5dGVzIHRvIGZsdXNoLiAq LwogICAgICAgaWYgKCFwdHIgJiYgbGVuID09IFVJTl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X21hc3Rlcjo6Y2xvc2Ug KCkKICAgZWxzZSBpZiAob2JpLkhhbmRsZUNvdW50ID09IDEpCiAgICAgewog ICAgICAgdGVybWlvc19wcmludGYoIkNsb3NpbmcgbGFzdCBtYXN0ZXIgb2Yg cHR5JWQiLCBnZXRfbWlub3IgKCkpOworICAgICAgaWYgKGdldF90dHlwICgp LT5nZXRzaWQgKCkgPiAwKQorCWtpbGwgKGdldF90dHlwICgpLT5nZXRzaWQg KCksIFNJR0hVUCk7CiAgICAgICBTZXRFdmVudCAoaW5wdXRfYXZhaWxhYmxl X2V2ZW50KTsKICAgICB9CiAK --Multipart=_Sun__7_Jun_2015_09_03_29_+0900_uCisFul7s9sLIaAq Content-Type: text/plain; charset=us-ascii -- 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 --Multipart=_Sun__7_Jun_2015_09_03_29_+0900_uCisFul7s9sLIaAq--