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 12615 invoked from network); 3 Nov 2022 23:10:57 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 3 Nov 2022 23:10:57 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1667517057; b=X2SE9Cn2rA924ajIZTsSJEa1MeQRYlbLeCsrh78pIHbvtVx8h2bN96S/8kuC+Rc3+ih5emLTnT UcdbOrg74mz1FnjsByjXucGHJfJ1ozwcSoKzJz538yiwSJjn/46T7WlsmPUGua1pefMXdcOEGb Byfz37jKQsaOl8zVqgy8RGV97R/yRlXYyPvmUmlAjDskjnKS66NVhecr/aPzq24/x2vApRlVpq 2fCml1uP/7yUvJuaO0Yia2dS9Rc+J5aPCfzbO8wSF3OGvX1lOs6jBrf2B27iS2ZVS2ctGSg3KQ DGEAbZT7angOG/Yoe5RDOUWJH64VtaxWRluOIrMWWIYaJQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f43.google.com) smtp.remote-ip=209.85.218.43; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1667517057; bh=b9qBO3g4Q3lccoF0PsoHkCkq+E/fGmZ5mFkxHdJzzqo=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=fLaQCXAzWoRTjibG6f3lezlxIlNM4M9cuXH7k6MWM0/2Yox2Dga54/AShP81JiMCNTfFDuGHIT mOuhUxpj/3CDUoDefSWuUhJ/FMiCZfbQUHAFsi5QYj8igZ+VfuL6qkd91a/5xnLtRXfbvfaYxz BQpkCkf4qqgGMkt/HlbYIouExlyKCJrPN/e89BdkIkQ3QuNFlcfm4ctpkRbYWVbDcVY/7roUCi em5MQkGuFY8rZJTl95dHcd5ZYvrziJP0DDDl2nw47LxYk7Hwnz+SSYpQezveQaA5+xiIgI9SQg b4hmSbhs7k5TvYDHynEBKzQqCd1eoWwvMx+w1ZOCyMlBSg==; 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:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=DMpbkVBYifs5msqyCkNWMm4V5HL+aaN+/RLlyyZSJhk=; b=B0m1TtSGZW/7ZD0q9dG7FQJxBB GxnVX3ZffmlnKr0IX/sJZv4l6sO8jq/tZnBeFi8wTs3C5vk6xORLqxy02Z1f2v/3FpPrvY6BHynBV LMizHi10OMq0i+EkgDV0+yhvZgk5utlRVV/Ee8BObrQnn5eB+olcOks6JDsHyfdajSX1udcrqM/Q6 VJmg+fuKvoTpZxkdcssSaXv8W4+/DxxOjvBHDI5K+mnMEaVYID2s0KJC61VYamKUa7hkS99NA0Mb8 +CQqOcOcNNKrMsQoZj8z8M3ZfqoKCMElfL5WJ2Z09YObKjeq/OHnO7q8M2tlOH7z2dUACb/5c3H1Y 0l+LfOLQ==; Received: by zero.zsh.org with local id 1oqjMN-000NCf-Vg; Thu, 03 Nov 2022 23:10:55 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f43.google.com) smtp.remote-ip=209.85.218.43; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f43.google.com ([209.85.218.43]:35572) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1oqjM4-000Muo-7C; Thu, 03 Nov 2022 23:10:37 +0000 Received: by mail-ej1-f43.google.com with SMTP id k2so9249328ejr.2 for ; Thu, 03 Nov 2022 16:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=DMpbkVBYifs5msqyCkNWMm4V5HL+aaN+/RLlyyZSJhk=; b=53fR7iqMAmjuZl/VaumNlugGsJ/9+X347AHOz2IgBlthEuFU83EbI6MTj2jngQyrjX ZSX+jQyumGjnpT9TQaUIXC4VrraILOLUuTZ0xJTxCguqcjtzjFLulW4RHRyTqEDQEjfe xNOI7l9JBDXhxMuFFzAentv9O91qyhvM6zP0qIbP7wSbJsDPkDDZAIPaMlly37D7Oouf FiFeiT1Tr89zQIWC13yn9E7cdAEpXYdyJ+HuHFzMvGJ6ckpgMsqbWKmEV8VbgO2ZjOMz Ip/dah+4VVf4P4oJoaVQTHAzHoKo85ZdnOgJ+m6ZtBx0lT+e5A6oYQt3JxIkB7sPCYRb Xenw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DMpbkVBYifs5msqyCkNWMm4V5HL+aaN+/RLlyyZSJhk=; b=7eRAvFeMxrfe67N67dCpQDrxx0rUzJ62dZaZj6cP0HePP61z+JEMdr497XO8Fvj6PG rML0QJbspfi7K3qFLTqkpCGDkcLqhHkYZxE4WWe8TBz8XO39tKcBzSABbpx3tulglxRl ErjS3+5P4PUd81lM4tNxeeuSGUj0GDvn9w7pnpePHnyLPUho1R9C9KqIW7txEdRF/Hmo T3dNHRTlPplesEJmMLhqrR/KrItjtwFddW9aevc66bnnhh+3SoGCmkzFfk63cBjn27fi s7Bu+YFuawNKQJIDZxX6Tpv98G0+kObX/+8AjMrAyZtoAPeZsW0r1QRVbkJ7yGZMA/NX OLEA== X-Gm-Message-State: ACrzQf0h2J667NKwLC6BdBqlBPYRdqlru9x6PD/On8OSFsAua9amoiIp sPqsZTXXdfaddGxm/pW7FndAMZM3+YZn36rNip0H700Cz/jRlw== X-Google-Smtp-Source: AMsMyM5Yt+Eb2h9cid+LvLEevy+0xl4VtW5q2bwTbIVGulvjCNF/Wal49vuZomvmxacqsI4wr/xW+b9de9fZytFvZ5o= X-Received: by 2002:a17:906:58c7:b0:722:f4bf:cb75 with SMTP id e7-20020a17090658c700b00722f4bfcb75mr30986154ejs.450.1667517035446; Thu, 03 Nov 2022 16:10:35 -0700 (PDT) MIME-Version: 1.0 References: <2FE96386-2D04-434F-AD2F-F08356B1AE04@kba.biglobe.ne.jp> In-Reply-To: From: Bart Schaefer Date: Thu, 3 Nov 2022 16:10:24 -0700 Message-ID: Subject: Re: problem with 'ls | less' shell function To: Jun T Cc: zsh-workers@zsh.org Content-Type: text/plain; charset="UTF-8" X-Seq: 50860 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: On Sat, Oct 22, 2022 at 4:43 PM Bart Schaefer wrote: > > So as far as zsh knows, the attachtty() was successful, but if the > debugger is telling the truth, something is resetting the tty pgrp > again without attachtty() being called. A little further ... I instrumented jobs.c:makerunning() -- % dir() { ls -lrRt | less } % dir ^Z % fg makerunning: PID 79731 job 1 jn->stat: 9427 makerunning: PID 79731 job 2 jn->stat: 370 [1] + continued ls -lrRt | makerunning: PID 79731 job 1 jn->stat: 9425 makerunning: PID 79731 job 2 jn->stat: 368 zsh: suspended (tty output) ls -lrRt | zsh: suspended (tty output) ls -lrRt | With an anonymous function instead of a named one, this doesn't happen and "fg" works: % () { ls -lrRt | less } ^Z % fg makerunning: PID 79731 job 3 jn->stat: 82 [3] - continued ls -lrRt | makerunning: PID 79731 job 3 jn->stat: 80 9427 is CHANGED|STOPPED|LOCKED|INUSE|SUPERJOB|CURSH|SUBLEADER 370 is STOPPED|LOCKED|NOPRINT|INUSE|SUBJOB 82 is STOPPED|LOCKED|INUSE So we can remove at least one makerunning(), I think from bin_fg(). But I then instrumented update_job() where "continued..." is printed, and: % fg [1] + suspended ls -lrRt | makerunning: PID 687 job 1 jn->stat: 9427 makerunning: PID 687 job 2 jn->stat: 370 zsh: wait_for_processes after SIGCHLD zsh: update_job signals.c L559 zsh: update_job signals.c L559 update_job: stopping gleader zsh: suspended (tty output) ls -lrRt | zsh: suspended (tty output) ls -lrRt | Aha. So there's a race condition of sorts, just one that we always lose. We send a SIGCONT to the process group for the forked job, which wakes up both the subjob and the superjob, but when we get the SIGCHLD for the subjob we decide that its superjob is running not because we just restarted it, but because it is still waiting to be stopped from the previous SIGTSTP. I haven't worked out if this means there's an order of signal delivery issue or just that we botched some internal state.