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 <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #11828
This commit is contained in:
наб 2021-04-03 01:34:58 +02:00 committed by Brian Behlendorf
parent d539b77934
commit 35cce6ea63
3 changed files with 8 additions and 9 deletions

1
contrib/bash_completion.d/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/zfs

View File

@ -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)

View File

@ -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