summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorнаб <[email protected]>2021-04-03 01:34:58 +0200
committerGitHub <[email protected]>2021-04-02 16:34:58 -0700
commit943df59ed942182427ed50b94a346dc22c4407e6 (patch)
tree2537f0d6c55631bac78732cefa9f38b9c3adf51d
parentc0af3c7b2c7bf1c601b4130533a9efebe42c581c (diff)
bash_completion.d: always call zfs/zpool binaries directly
/dev/zfs is 0:0 666 on most systems, so the [ -w /dev/zfs ] check always succeeds, but if zfs isn't in $PATH (e.g. when completing from "/sbin/zfs list" on a regular account) this can lead to error spew like nabijaczleweli@szarotka:~$ /sbin/zfs list bash: zfs: command not found @ bash: zfs: command not found We only do read-only commands, and quite general ones at that, so there's no need to elevate one way or another. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #11828
-rw-r--r--contrib/bash_completion.d/.gitignore1
-rw-r--r--contrib/bash_completion.d/Makefile.am5
-rw-r--r--contrib/bash_completion.d/zfs.in (renamed from contrib/bash_completion.d/zfs)11
3 files changed, 8 insertions, 9 deletions
diff --git a/contrib/bash_completion.d/.gitignore b/contrib/bash_completion.d/.gitignore
new file mode 100644
index 000000000..0fd9cc63a
--- /dev/null
+++ b/contrib/bash_completion.d/.gitignore
@@ -0,0 +1 @@
+/zfs
diff --git a/contrib/bash_completion.d/Makefile.am b/contrib/bash_completion.d/Makefile.am
index 4f13af6b3..8fbe03688 100644
--- a/contrib/bash_completion.d/Makefile.am
+++ b/contrib/bash_completion.d/Makefile.am
@@ -1,5 +1,8 @@
+include $(top_srcdir)/config/Substfiles.am
+
bashcompletiondir = $(sysconfdir)/bash_completion.d
noinst_DATA = zfs
-EXTRA_DIST = $(noinst_DATA)
+EXTRA_DIST += $(noinst_DATA)
+SUBSTFILES += $(noinst_DATA)
diff --git a/contrib/bash_completion.d/zfs b/contrib/bash_completion.d/zfs.in
index 094527340..8898fc735 100644
--- a/contrib/bash_completion.d/zfs
+++ b/contrib/bash_completion.d/zfs.in
@@ -21,13 +21,8 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
-if [[ -w /dev/zfs ]]; then
- __ZFS_CMD="zfs"
- __ZPOOL_CMD="zpool"
-else
- __ZFS_CMD="sudo zfs"
- __ZPOOL_CMD="sudo zpool"
-fi
+__ZFS_CMD="@sbindir@/zfs"
+__ZPOOL_CMD="@sbindir@/zpool"
# Disable bash's built-in hostname completion, as this makes it impossible to
# provide completions containing an @-sign, which is necessary for completing
@@ -198,7 +193,7 @@ __zfs_complete_multiple_options()
COMPREPLY=($(compgen -W "$options" -- "${cur##*,}"))
local existing_opts=$(expr "$cur" : '\(.*,\)')
- if [[ $existing_opts ]]
+ if [[ $existing_opts ]]
then
COMPREPLY=( "${COMPREPLY[@]/#/${existing_opts}}" )
fi