Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libvirt] Bash syntax error #147

Closed
telometto opened this issue Nov 7, 2021 · 5 comments
Closed

[libvirt] Bash syntax error #147

telometto opened this issue Nov 7, 2021 · 5 comments
Labels
compatibility External Problem/Bug Problems/Bugs of other projects

Comments

@telometto
Copy link

ble version: 0.4.0-devel3+2243e91
Bash version: 5.1.8(1)-release (x86_64-redhat-linux-gnu)

I'm experiencing a weird bug when I try to autocomplete the virsh command (so far, this is the only one I've found this happens with): basically, bash tells me there's a syntax error, as you can see from the screenshot below.
scrot_edit

I am 100% sure that it's an issue with ble, since commenting out (i.e. disabling) the source at the end of my .bashrc does not reproduce the error.

Thanks~

@akinomyoga
Copy link
Owner

Sorry for the late reply. I'm sorry but now am extremely busy. I hope I can respond in detail this weekend.

At the moment, the problem is not observed in my environment.

  • Q1 Could you check if the problem reproduces with only the plain Bash plus ble.sh without any user other configuration? This is important to narrow down the condition that the problem arises. Thank you.

@telometto
Copy link
Author

Sorry for the late reply. I'm sorry but now am extremely busy. I hope I can respond in detail this weekend.

Don't worry, I have plenty of time ^_^ Besides, I'm only experiencing the issue when I try to autocomplete virsh commands.

  • Q1 Could you check if the problem reproduces with only the plain Bash plus ble.sh without any user other configuration? This is important to narrow down the condition that the problem arises. Thank you.

I have tested it out on the default .bashrc and can confirm that the issue still happens. I'm using Fedora 35 and I didn't have this issue on F34, so I'm starting to suspect that it might be a conflict between some system configuration file and ble.

@akinomyoga
Copy link
Owner

akinomyoga commented Nov 14, 2021

I confirmed it in fc35. This is a bug of the bash-completion script for virsh (libvirt-client), /usr/share/bash-completion/completions/virsh, contained in the package libvirt-client-7.6.0-3.fc35.x86_64.

Description

The script overwrites the IFS environment variable on query for completions. You can confirm the problem without ble.sh by the following commands:

# Start a session without ble.sh

$ declare -p IFS | cat -A
declare -- IFS=" ^I$
"$
$ virsh a[TAB][TAB]
allocpages    attach-device    attach-disk    attach-interface    autostart
$ virsh a[C-c]
$ declare -p IFS | cat -A
declare -- IFS="$
"$

Originally the value of IFS is IFS=$' \t\n', but it becomes IFS=$'\n' after the trial of the completion. After this, word splitting will not be processed as normal:

$ a='a b c'
$ printf '<%s>\n' $a
<a>
<b>
<c>
$ virsh a[TAB][TAB][C-c]
$ printf '<%s>\n' $a
<a b c>

The shell variable word is also affected by the virsh completion.

Fix

The completion function _virsh_complete should declare IFS and word as local before changing them.

diff --git a/tools/bash-completion/vsh.in b/tools/bash-completion/vsh.in
index 70ade50a02..4399ff0a64 100644
--- a/tools/bash-completion/vsh.in
+++ b/tools/bash-completion/vsh.in
@@ -4,7 +4,7 @@

 _@command@_complete()
 {
-    local words cword c=0 i=0 cur RO URI CMDLINE INPUT A
+    local words cword c=0 i=0 cur word RO URI CMDLINE INPUT A

     # Here, $COMP_WORDS is an array of words on the bash
     # command line that user wants to complete. However, when
@@ -56,7 +56,8 @@ _@command@_complete()
     # the name of the command whose arguments are being
     # completed.
     # Therefore, we might just run $1.
-    IFS=$'\n' A=($($1 ${CMDLINE[@]} complete -- "${INPUT[@]}" 2>/dev/null))
+    local IFS=$'\n'
+    A=($($1 ${CMDLINE[@]} complete -- "${INPUT[@]}" 2>/dev/null))

     COMPREPLY=($(compgen -W "${A[*]%--}" -- ${cur}))
     __ltrim_colon_completions "$cur"
--
2.21.3

Reference

Report

I think I'll later add a workaround for this completion script at the ble.sh side.

@akinomyoga akinomyoga added External Problem/Bug Problems/Bugs of other projects compatibility labels Nov 14, 2021
@akinomyoga akinomyoga changed the title Bash syntax error [libvirt] Bash syntax error Nov 14, 2021
@telometto
Copy link
Author

Ah, so it's as I suspected. If you already have sent a patch to the maintainers, then I won't submit a bug report.
I'll just wait for when this gets gets patched upstream, as it's not of vital importance to me.

Thank you for your help ^_^

@akinomyoga akinomyoga reopened this Nov 14, 2021
@akinomyoga
Copy link
Owner

The patch has been accepted in the upstream: libvirt/libvirt @097296c3.

I think it would take some time for the patch to be applied to the distributed versions, so I added a workaround for this problem to ble.sh in commit f985b9a.

Thank you for reporting the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility External Problem/Bug Problems/Bugs of other projects
Projects
None yet
Development

No branches or pull requests

2 participants