From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 745 invoked from network); 4 Nov 2022 15:11:40 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 4 Nov 2022 15:11:40 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1667574700; b=UBq6ZNXbrzSsK3GNPnbihCvQe3Cz4irmegYYrD0mGSJgskVANcMXs/NW+DkxUgzmQoJnRRuyUK oRHKkHQ2KFXA2rVZ+mQWkpWbA5rQ3FfqH2TyPlLQUNZ8+0msIwTP2GH7IRxZjgyKDZj/jU+j48 Jxhcsx6nJzuuz/mASyW9od62lq4aSIsGUbMtroFHFqpr+75+f2oWS3ZqYpCUYj8o8E98WP9fid nCgt1Mi/Sj2t6B3/A1qluqqkcLKQfSYCMm2fpxVgphKFT+rqh3voISaGx+eeQ/J1J8+ASSxG0G HpNzuggaj0OipvPz9TfXVG+EKziqtF4C5U/qnMqAKaLF1A==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (snd00002-bg.im.kddi.ne.jp) smtp.remote-ip=27.86.113.2; dmarc=none header.from=kba.biglobe.ne.jp; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1667574700; bh=dj0LGRglA9Pz1DXG8lqOPcfEMRTq5418y/13xV2XczI=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Message-ID:In-Reply-To:To:References:Date:Subject: MIME-Version:Content-Transfer-Encoding:Content-Type:From:DKIM-Signature; b=Eo80mUCcrYRQvbEwPHLx1I8S4e18JD5B86sjm8wjyZf8hFvtWQYEFvnJs1jtwWQCInq1rWGuiD 7gm1WHR7LcuKycQi0bhwRmFGfQwJ2xzWY+TWuMWG2wJRhT3FdUQuiNytg0an2uTvTkPdS5fjUF hRZFJftY41ogfOaknI9BnAMQZzt7kqhFJ6OLUV2j6YgUMKkpd4Iw3RhL7crg06J1xaIyPhlv4U FJqSF7kxeNhZ6rcISTtHpz/wI+ICrET4CUXWDCJcpv5oQ18w4j7foTP5BFzXa3f4vNS0/+gtF/ dl/1f9AvypV+XK4jaUGpTWGFpKelMZBf84ao6OfEJxvL9w==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-Id:In-Reply-To:To:References: Date:Subject:Mime-Version:Content-Transfer-Encoding:Content-Type:From: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=66Sqw2yKuUGiRj/NFWGvaIJr9tdtcO7ABY8Epxxu/pY=; b=WIlDVl1RtTTb3igpyp2ddPyj35 CtBNGDb/U9DHiQY6loyUttGR73CdYViROsHEsDVHpQP0P3iiWMKIhx9FOKOtr0OqHAejvK9A1ux8H j+uLzLZd39YjNfJ92LaVks+27AQg/Xbr/85ntK6kwYbsd4diWCahXZiweOD1pyC7X9PR2927rgPe5 AwawGBXWwtabd0zjS5iEC4nl6JLAJwMtRu82CZrGp/R4Vi9HYfoxHRwzwveHzCbidOmcKjKmwxgg9 gY6nIl3u6Z6OM5knLtyUWYIOoBYeVSatXpKT1NW5dzHdfNjdz5yQ4VzPQ3Ya47ZffCyQ86+Hgr1ND xTA18W3w==; Received: by zero.zsh.org with local id 1oqyM7-0000l6-Mk; Fri, 04 Nov 2022 15:11:39 +0000 Authentication-Results: zsh.org; iprev=pass (snd00002-bg.im.kddi.ne.jp) smtp.remote-ip=27.86.113.2; dmarc=none header.from=kba.biglobe.ne.jp; arc=none Received: from snd00002-bg.im.kddi.ne.jp ([27.86.113.2]:62241 helo=dfmta0006.biglobe.ne.jp) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1oqyLX-0000O3-Av; Fri, 04 Nov 2022 15:11:05 +0000 Received: from mail.biglobe.ne.jp by omta0006.biglobe.ne.jp with ESMTP id <20221104151056997.IUXO.99066.mail.biglobe.ne.jp@biglobe.ne.jp> for ; Sat, 5 Nov 2022 00:10:56 +0900 From: Jun T Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.21\)) Subject: Re: [PATCH] problem with 'ls | less' shell function Date: Sat, 5 Nov 2022 00:10:56 +0900 References: <2FE96386-2D04-434F-AD2F-F08356B1AE04@kba.biglobe.ne.jp> To: zsh-workers@zsh.org In-Reply-To: Message-Id: <7BB37CE7-16A2-4079-956B-802E3FB4DC82@kba.biglobe.ne.jp> X-Mailer: Apple Mail (2.3445.104.21) X-Biglobe-Sender: takimoto-j@kba.biglobe.ne.jp X-Seq: 50871 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: > 2022/11/04 15:09, Bart Schaefer wrote: >=20 > Unfortunately, that leaves us with another example in 50105 still = unfixed: >=20 > ( zsh -fc 'print a few words; /bin/sleep 10' ) | { head -n 1 } The main zsh (zsh0, pid=3Dpgid=3D100) forks two times; the 1st one exec 'zsh -fc' (zsh1, pid=3D101), the 2nd one 'head' = (pid=3D102). Both are in the process group pgid=3D101, and the group becomes = foreground. But it seems these two are in different jobs (because of { head } ?). Then zsh1 exec 'sleep 100' (without forking). Now 'sleep 100' has = pid=3D101 and pgid=3D101. When 'head' exits, zsh0 calls update_job(). In this function: 548 /* is this job in the foreground of an interactive shell? */ 549 if (mypgrp !=3D pgrp && inforeground && 550 (jn->gleader =3D=3D pgrp || 551 (pgrp > 1 && =20 552 (kill(-pgrp, 0) =3D=3D -1 && errno =3D=3D ESRCH)))) { mypgrp=3D100, pgrp=3D101, jn->gleader=3D101, and the if(...) holds, and = the line 568 jn->stat |=3D STAT_ATTACH; =20 is executed. Since { head } is a separate job and head has exited, the job will be removed, and attachtty(mypgrp=3D100) will be called when the job is removed. Then pgid=3D101 (=3Dsleep 100) lose tty.=20 But why just "jn->gleader =3D=3D pgrp" is enough to assume that the = foreground job has finished? If the line 550 above is replaced by 550 ( then ^C works for [1] ( zsh -fc 'print a few words; /bin/sleep 10' ) | { head -n 1 } But now we need two ^C's to kill [2] { sleep 10; sleep 20; } | { sleep 30; sleep 40; } Another code that looks suspicious to me is (also in jobs.c) 478 if (pn->pid =3D=3D jn->gleader) /* if this process is = process group leader */ 479 status =3D pn->status; 480 } The 'status' is later used at (line numbers after the patch = pipejobs.txt): 641 if (inforeground =3D=3D 2 && isset(MONITOR) && = WIFSIGNALED(status)) { When 'sleep 30' is killed, pn->pid=3D(pid of sleep 30), but it is not = equal to jn->gleader (=3D probably 'sleep 10'?). Then if() at line 641 does = not hold, and 'sleep 40' will be started. If the line 478 is replaced by 478 if (WIFSIGNALED(pn->status) || pn->pid =3D=3D jn->gleader) then [2] can be killed by a single ^C. But I guess it will have bad side effects. And ^Z/fg (still) does not work for [2]. Sorry, I have no time now to investigate further.=