scp/rsync autocomplete can hang if command-not-found enabled

Bug #1534175 reported by Jonathan
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
command-not-found
New
Undecided
Unassigned

Bug Description

Referencing my post at http://superuser.com/a/1026307/156478

AlexO'Neill wrote:

>Here is my scenario:
>
>I want to transfer ~/foo.txt to a server aoneill@bar.
>
>I start typing in my command line:
>
>aoneill@aoneill-Laptop:~$ scp fo
>
>At this point I hit <tab> to complete the file name, and my terminal just freezes up. It won't change based on any keystroke, and the cursor is just stuck right next to the fo, unless I <ctrl-C> out.
>

Using set -x shows that the autocomplete was hanging on ruptime.

 $ set -x
 $ scp fo local cur prev words cword
+ _init_completion -n :
...
+ COMPREPLY+=($( compgen -W "$( ruptime 2>/dev/null | awk '!/^ruptime:/ { print $1 }' )" -- "$cur" ))
+++ ruptime
+++ awk '!/^ruptime:/ { print $1 }'

When I tried to run ruptime myself I found that it wasn't installed. After installing the rwho package the hang was fixed.

sudo apt-get install rwho

The COMPREPLY line calls ruptime without checking to see if it exists. And since I have 'COMMAND_NOT_FOUND_INSTALL_PROMPT=1' enabled the command tries to ask me if I want to install it but the pipe captures the output and hangs.

So the bug happens because command-not-found doesn't check if its being used in a pipe.

The simplest reproduction of this bug was running the following command "wdf 2>/dev/null | grep asdf" assuming wdf isn't installed and is a valid command.

I've attached an example patch that checks whether the command is attached to a real terminal before continuing.

Revision history for this message
Jonathan (jjcf89) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.