Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID
	autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=brasslantern-com.20150623.gappssmtp.com; s=20150623;
        h=mime-version:in-reply-to:references:date:message-id:subject:from:to
         :cc;
        bh=Jo9I1/teeRb+JSHB1hV1aNz1vdH2u0ZLB6hMmuO42VU=;
        b=ncb7FBFlx2d8ksDhAdVoosl29AjNkrKiB53krpAiKrxDXrSX/jncaUR0dRjYKOdFB7
         Le7Yg5nJfoAxRGd/nUHXiCO7ZnAPerVYJOeIhhQEc03glIQM4hiVDtHvDsATETZVG1Ox
         sSx1CuQ63CdLu3H350Xnrf5XwjYpHKOQI/2G/jeDdQuLr/L977debGiy4WYFnJDJskDT
         ab1efE5tP6gfD5suVZJmPzCUgzSel3OucsjOVI8ee/qJUyv1gxVWAR6yvysBClqZokbu
         g5hckqS57+C4V0sByPq4qgBpSk5ZtwYcZqNFpZYXyfUPQBX18+BzXybdY1o61ptqL3WE
         b41g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:date
         :message-id:subject:from:to:cc;
        bh=Jo9I1/teeRb+JSHB1hV1aNz1vdH2u0ZLB6hMmuO42VU=;
        b=DYgj6nQBtyRVFMzcnAkycBV1QsrdwlGgRqmTTrvY7qbNT3BxIEg7bsjYF3KQJ24TxE
         HVJ6yOQy+0mW5RG8hxnO8bmZOYzzB5aTqz6PeaNdxFIFeLWGJRivKSyzH7BR//KOqwC2
         M3PaAXDqhqfrZ2cgABK9OJOY6fOEKU01LtscUvLEpLJfxxZogbMhLL506TvhtBmdshnN
         AnHDCB0LHDejKXqmFHyzo1nsso0ssOvIKZzcjgDM+y7LfjUbHsBtFGZqewKDdQ/Es4JZ
         nzg3q+HH2WYCoQ/HcSJxueecwPwGiZpsQ+EG3tcu5VfiNLsnRc0vrfaAYo7GA2Y7NzrR
         6k1Q==
X-Gm-Message-State: AOPr4FUdyJNtfttHG7FvGM1i4cD+FddPqrLyCuRKZlBHN+Sw5IIuHhf3vwlAFa+bVzKk6+9kohQ0L60nsMhAig==
MIME-Version: 1.0
X-Received: by 10.112.199.198 with SMTP id jm6mr3042725lbc.80.1462334174490;
 Tue, 03 May 2016 20:56:14 -0700 (PDT)
In-Reply-To: <ufaa8k6ei8t.fsf@epithumia.math.uh.edu>
References: <ufaa8k6ei8t.fsf@epithumia.math.uh.edu>
Date: Tue, 3 May 2016 20:56:14 -0700
Message-ID: <CAH+w=7b+tKnvfv1ip6ykNW4Oh_BQSiXnGwGMQzhvfi=Wrq6DXg@mail.gmail.com>
Subject: Re: Weird issue with pipeviewer and multiple pipes
From: Bart Schaefer <schaefer@brasslantern.com>
To: Jason L Tibbitts III <tibbs@math.uh.edu>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Content-Type: text/plain; charset=UTF-8
X-Seq: zsh-workers 38398

On Tue, May 3, 2016 at 6:15 PM, Jason L Tibbitts III <tibbs@math.uh.edu> wrote:
>
> [2]  + 11459 done                    echo 1 |
>        11461 suspended (tty output)  pv -l -s $(echo 1) |
>        11462 interrupt               cat

Something weird is definitely going on with pv, because it's receiving
a TTOU signal even when the terminal stty setting is supposed to
suppress that.

It doesn't happen with "-s 1" in place of the $(echo 1) substitution,
but it also doesn't happen if pv is replaced by e.g. tee $(echo
/dev/fd/2), so it's some combination of using command substitution and
something pv is doing.  By examination of strace output, it has to be
ioctl(2, TCSETS, ...).

So what is pv doing with that ioctl()?  (There doesn't seem to be a
way to get strace to both print the entire structure and decode it
from hexadecimal.)  I suspect that it's putting itself in its own
process group, which means that kills of the parent job don't reach it
any longer, which is why zsh ends up waiting forever when it tries to
resume the whole pipeline.  But I don't know why the $(echo) makes any
difference to it receiving the TTOU in the first place.

All of these also avoid the problem:

    echo 1 | { trap '' TTOU ; pv -p -s $(echo 1) } | cat
    echo 1 | pv -p -s $(echo 1) 2>/dev/tty | cat
    echo 1 | { x=$(echo 1); pv -p -s $x } | cat

> If I type fg, the shell is pretty much hung.  You have to kill -9 the pv
> process either way to get rid of the job.  (Lesser kills don't seem to
> work.)

Lesser kills do work, you just have to follow them with -CONT to
resume the stopped process; e.g. with GNU killall,
  killall pv
  killall -CONT pv

