OndrejHome / fast-vm

'fast-vm' is a script for defining VMs from images provided in thin LVM pool.
GNU General Public License v3.0
22 stars 14 forks source link

`fast-vm import_image` sets `stty -echo` when used with `pv` #50

Closed vashirov closed 4 years ago

vashirov commented 4 years ago

After fast-vm import_image I have to run stty sane or stty echo to restore echo in my terminal. This only happens in bash when pv is installed and is used by fast-vm. In zsh I don't have this problem.

$ stty -a
speed 38400 baud; rows 43; columns 173; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V;
discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc

$ fast-vm import_image fedora29 http://ftp.linux.cz/pub/linux/people/ondrej_famera/fastvm-images/generated/6g__fedora-29.img.xz https://raw.githubusercontent.com/OndrejHome/fast-vm-public-images/master/fedora/xml/fedora-28-current.xml https://raw.githubusercontent.com/OndrejHome/fast-vm-public-images/master/fedora/hacks/6g_fedora-29-hacks.sh  
[__][inf] provided empty file path
[__][inf] Detected remote file with size 340209204
[__][inf] provided empty file path
[__][inf] Detected remote file with size 1443
[__][inf] downloading https://raw.githubusercontent.com/OndrejHome/fast-vm-public-images/master/fedora/xml/fedora-28-current.xml
[__]into /tmp/tmp.cmmaqLbyiL
[__][inf] provided empty file path
[__][inf] Detected remote file with size 793
[__][inf] downloading https://raw.githubusercontent.com/OndrejHome/fast-vm-public-images/master/fedora/hacks/6g_fedora-29-hacks.sh
[__]into /tmp/tmp.GrKEP8Whc1
[__][inf] Size of image was determined from the filename to be 6G.
[__][inf] creating LV fastvm-fedora29 ...
[__][inf] importing image http://ftp.linux.cz/pub/linux/people/ondrej_famera/fastvm-images/generated/6g__fedora-29.img.xz into /dev/serenity/fastvm-fedora29
 download:  324MiB 0:00:44 [7.35MiB/s] [==================================================================================================================>] 100%            
   unpack: 6.00GiB 0:00:45 [ 133MiB/s] [==================================================================================================================>] 100%            
0+767635 records in
0+767635 records out
6442450944 bytes (6.4 GB, 6.0 GiB) copied, 45.8734 s, 140 MB/s
[__][ok] Image fedora29 imported

# at this point there is no echo
$ speed 38400 baud; rows 43; columns 173; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V;
discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig -icanon iexten -echo echoe echok -echonl -noflsh -xcase tostop -echoprt echoctl echoke -flusho -extproc

Apparently pv -c is known for this kind of behavior: https://serverfault.com/a/690183

The workaround would be to run stty sane or stty echo after pv -c invocation.

OndrejHome commented 4 years ago

Hi @vashirov , Thank you for reporting the issue and additional information about zsh. I think I have noticed same thing in past and thought that it might be just something wrong on my system, but checking the link you have provided it seems that really the -c option of pv might be the root cause for this. I'm using only bash. If this is indeed the behaviour of pv in bash then I would like to rather see it fixed in pv instead of introducing the workarounds in fast-vm. But before getting to conclusions let me do some testing on systems where I have tested the fast-vm to see the whole picture.

Could you please let me know in the meantime the following information?

I will have a look at this either today or during next week. Thank you!

vashirov commented 4 years ago

I also tested in zsh a bit more and noticed that it's also affected, but it happens less often than in bash. So I also think that the root cause is pv -c and its behavior might be racy. I've sent bug report to the author.

I used the following reproducer:

dd if=/dev/zero bs=1M count=1024 | pv -cN download | pv -cN unpack | dd of=/dev/null; stty -a | grep echo

You might want to increase count in case it's too fast.

OndrejHome commented 4 years ago

Thank you for additional information. I had to crank up the count a bit (6000 made it up on my Gentoo system while new CentOS 8 system resisted a bit longer), but then on second try the echo really disappeared. Tested on my Gentoo GNU bash, version 4.4.23(1)-release (x86_64-pc-linux-gnu).

While it would be nice to fix it in the pv I think I will also implement the workaround in the fast-vm so if it detects that stty -a echo state has changed from echo to -echo it will re-enable it. I will post the proposed change in second half of this week. I will keep you updated.

In case you get any response from pv author in the meantime please also let me know.

OndrejHome commented 4 years ago

Hi @vashirov, thank you for patience. I have tested workaround in fast-vm to restore stty to previous values when the echo is detected to be missing after pv -c. I have tested this on my Gentoo and CentOS-8.0. Currently the change is in develop branch. I'm planning on making release of new version of fast-vm in upcoming weeks when it would be available as package with other fixes and improvements.

In the meantime, would you be able to test the changes from commit d433db64585dda3566ba45254ac4b6eeb4b37adb on your machine and let me know if it works also for you? Change introduces also message that shows when issue was detected and recovery was attempted. So you should see message [__][inf] Missing 'echo' on termninal after 'pv', restoring terminal settings before 'pv'. when issue happened. After that the terminal should work normally. If that is not the case, please let me know. Once again thank you for reporting this issue and providing the needed details.

OndrejHome commented 4 years ago

Hi @vashirov, the change is now available in fast-vm version 1.6 released this week. If you have oportunity to confirm if this works also for you or you need more time to test it please let me know. If there will be no response from you for 2 weeks I will proceed with closing this Issue as I cannot reproduce the issue any more after implementing the workaround that restores echo in terminal in my environment.

vashirov commented 4 years ago

Hi @OndrejHome, I apologize for the delay. I still haven't heard from the author of pv. I've tested fast-vm-1.6-1.fc30.noarch. Everything works as expected. Thank you so much for fixing this issue! And thank you for fast-vm, really enjoying it.