Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.bugs.dist > #882737

Bug#890901: multiple pv -c : terminal left in -icanon -echo tostop

Path csiph.com!aioe.org!bofh.it!news.nic.it!robomod
From Andrew Wood <andrew.wood@ivarch.com>
Newsgroups linux.debian.bugs.dist
Subject Bug#890901: multiple pv -c : terminal left in -icanon -echo tostop
Date Tue, 20 Feb 2018 19:00:01 +0100
Message-ID <vlkmR-3JB-13@gated-at.bofh.it> (permalink)
References <vlfwR-DM-9@gated-at.bofh.it> <vlfwR-DM-9@gated-at.bofh.it>
X-Original-To Lars Ellenberg <lars.ellenberg@linbit.com>, 890901@bugs.debian.org
X-Mailbox-Line From debian-bugs-dist-request@lists.debian.org Tue Feb 20 17:57:10 2018
Old-Return-Path <debbugs@buxtehude.debian.org>
X-Spam-Flag NO
X-Spam-Score -3.961
Reply-To Andrew Wood <andrew.wood@ivarch.com>, 890901@bugs.debian.org
Resent-To debian-bugs-dist@lists.debian.org
Resent-Cc Antoine Beaupré <anarcat@debian.org>
X-Debian-Pr-Message followup 890901
X-Debian-Pr-Package pv
X-Debian-Pr-Source pv
X-Spam-Bayes score:0.0000 Tokens: new, 42; hammy, 150; neutral, 153; spammy, 0. spammytokens: hammytokens:0.000-+--58PM, 0.000-+--work-around, 0.000-+--Maintainer, 0.000-+--Severity, 0.000-+--1.6.6-1
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
User-Agent Mutt/1.5.20 (2009-12-10)
X-Greylist delayed 1622 seconds by postgrey-1.36 at buxtehude; Tue, 20 Feb 2018 17:54:27 UTC
X-Debian-Message from BTS
X-Mailing-List <debian-bugs-dist@lists.debian.org> archive/latest/1442578
List-ID <debian-bugs-dist.lists.debian.org>
List-URL <https://lists.debian.org/debian-bugs-dist/>
Approved robomod@news.nic.it
Lines 120
Organization linux.* mail to news gateway
Sender robomod@news.nic.it
X-Original-Date Tue, 20 Feb 2018 17:27:20 +0000
X-Original-Message-ID <20180220172719.GA12723@ivarch.com>
X-Original-References <20180220124058.GA6733@soda.linbit> <20180220124058.GA6733@soda.linbit>
Xref csiph.com linux.debian.bugs.dist:882737

Show key headers only | View raw


Hello

Sorry for the delayed response.  I have received your other emails, but I am
quite far behind with my mailbox.

I have successfully reproduced the bug you describe, using the command line
you have provided.

Your suggested solution of storing the initial terminal state in the shared
memory segment sounds like a good one.  I should also be able to use the
test scenario you provided to write an automated test for this problem.

Thanks for the detailed bug report.


On Tue, Feb 20, 2018 at 01:40:58PM +0100, Lars Ellenberg wrote:
> Package: pv
> Version: 1.6.6-1
> Severity: normal
> 
> Dear Maintainer,
> 
> On almost every try,
>   seq 200 | pv -abc -N A | pv -abc -N B | pv -abc -N C > /dev/null
> leaves my terminal with echo disabled (no reaction to typing).
> 
> It can be restored by blindly typing "reset" and/or "stty sane".
> 
> This happens because of the following race condition:
> 
> The first "pv" to start stores current termios in its t_save,
> then changes it (disables echo).
> The next "pv" stores that already changed termios in its t_save.
> 
> The last one to terminate "restores" to its t_save,
> which can very well have echo disabled. D'uh.
> 
> debian testing pv 1.6.6-1
> (which looks like it is basically the latest upstream)
> 
> reproducing "single" bash line above,
> slightly more elaborate here,
> which also restores the termios settings in each iteration:
> 
> # btw, for me stty -g is:
> # 4500:5:bf:8a3b:3:1c:7f:15:4:0:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0
> stty_g=$(stty -g);
> i=0;
> while :; do
> 	printf "=== iteration: %3u\n" $(( ++i ));
> 	stty $stty_g;
> 	before=$(stty -a);
> 	seq 200 | pv -abc -N A | pv -abc -N B | pv -abc -N C > /dev/null;
> 	after=$(stty -a);
> 	stty $stty_g ;
> 	diff -U0 <(printf "%s\n" $before) <(printf "%s\n" $after) |
> 		grep -v '^@' |
> 		tee /dev/tty |
> 		grep -C10 echo && break;
> done
> 
> For me, it usually takes under 10 iterations,
> where "tostop" may remain earlier already,
> but eventually even "-echo -icanon" remains :-(
> 
> === iteration:   1
>         A:  692 B [17,4MiB/s]
>         C:  692 B [1,59MiB/s]
> --- /dev/fd/63  2018-02-10 18:18:50.297415510 +0100
> +++ /dev/fd/62  2018-02-10 18:18:50.297415510 +0100
> -icanon
> +-icanon
> -echo
> +-echo
> --tostop
> +tostop
> 
> 
> A likely more real-life reproducer is a pipe like
>  ... pv -abc -N in | xz -T2 -9 | pv -abc -N out ...
> 
> Maybe this could be fixed by storing not only the "crs_y_top",
> but also "t_save" in IPC shm (from the first pv, the one that
> initializes that shm segment while holding the tty lock),
> so the last one to terminate can restore the termios settings
> as found by the first one to start?
> 
> But that
>  (lock;
>    shm create and/or attach;
>    if creator
>       tcgetattr and save in shm,
>    else load from shm,
>       to be able to restore
>       should I be the last one to leave
>  unlock)
> would need to happen very early. I think pv_crs_ipcinit() is currently
> called too late, termios settings may have been changed already.
> 
> Anyways, such command lines usually are scripted,
> and a work-around exists: just enclose the pipe containing pv
> into stty_g=$(stty -g); pipe | goes | here; stty $stty_g
> as I did in my reproducer above,
> so "don't panic" ;-)
> 
> But maybe you can find a nice place to add this in?
> Or document the problem and the workaround?
> 
> Cheers,
> 
>     Lars
> 
> This mail was also sent
>  To: pv@ivarch.com, andrew.wood@ivarch.com
>  Date: Sat, 10 Feb 2018 19:07:42 +0100
>  Subject: multiple pv -c : terminal left in -icanon -echo tostop
>  Message-ID: <20180210180728.GH19196@soda.linbit>

-- 
Andrew Wood

Back to linux.debian.bugs.dist | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Bug#890901: multiple pv -c : terminal left in -icanon -echo tostop Lars Ellenberg <lars.ellenberg@linbit.com> - 2018-02-20 13:50 +0100
  Bug#890901: multiple pv -c : terminal left in -icanon -echo tostop Andrew Wood <andrew.wood@ivarch.com> - 2018-02-20 19:00 +0100

csiph-web