Skip to content

Commit cd37f6a

Browse files
zdykstramidzelis
andcommitted
zfsbootmenu-core: discard stderr on zfs/zpool cmds
Most interactions with zfs/zpool binaries shouldn't allow stderr to print to the controlling terminal, so just discard it. The few times it's useful, send it to stdout instead where it's captured by the subshell. Co-authored-by: Min Idzelis <[email protected]> Co-authored-by: Zach Dykstra <[email protected]> Closes: #583
1 parent 2611f36 commit cd37f6a

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

zfsbootmenu/lib/zfsbootmenu-core.sh

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ match_hostid() {
160160
fi
161161
;;
162162
esac
163-
done <<<"$( zpool import )"
163+
done <<<"$( zpool import 2>/dev/null )"
164164
fi
165165

166166
zdebug "importable pools: ${importable[*]}"
@@ -227,7 +227,7 @@ log_unimportable() {
227227
*)
228228
;;
229229
esac
230-
done <<<"$( zpool import )"
230+
done <<<"$( zpool import 2>/dev/null )"
231231
}
232232

233233
# args: none
@@ -239,7 +239,7 @@ check_for_pools() {
239239

240240
while read -r pool ; do
241241
[ -n "${pool}" ] && return 0
242-
done <<<"$( zpool list -H -o name )"
242+
done <<<"$( zpool list -H -o name 2>/dev/null )"
243243

244244
return 1
245245
}
@@ -612,7 +612,7 @@ create_snapshot() {
612612
load_key "${selected}"
613613

614614
zdebug "creating snapshot ${selected}@${target}"
615-
if ! output="$( zfs snapshot "${selected}@${target}" )" ; then
615+
if ! output="$( zfs snapshot "${selected}@${target}" 2>&1 )" ; then
616616
zdebug "unable to create snapshot: ${output}"
617617
return 1
618618
fi
@@ -677,7 +677,7 @@ rollback_snapshot() {
677677
CLEAR_SCREEN=1 load_key "${snap}"
678678

679679
zdebug "will roll back ${snap}"
680-
if ! output="$( zfs rollback -r "${snap}" )"; then
680+
if ! output="$( zfs rollback -r "${snap}" 2>&1 )"; then
681681
zerror "failed to roll back snapshot ${snap}"
682682
zerror "${output}"
683683
return 1
@@ -843,7 +843,7 @@ find_be_kernels() {
843843
zdebug "fs set to ${fs}"
844844

845845
# Try to mount, just skip the list otherwise
846-
if ! mnt="$( mount_zfs "${fs}" )"; then
846+
if ! mnt="$( mount_zfs "${fs}" 2>&1 )"; then
847847
zerror "unable to mount ${fs}"
848848
return 1
849849
fi
@@ -910,7 +910,7 @@ select_kernel() {
910910
kexec_args="$( tail -1 "${kernel_list}" )"
911911

912912
# If a specific kernel is listed, prefer it when possible
913-
specific_kernel="$( zfs get -H -o value org.zfsbootmenu:kernel "${zfsbe}" )"
913+
specific_kernel="$( zfs get -H -o value org.zfsbootmenu:kernel "${zfsbe}" 2>/dev/null )"
914914
if [ "${specific_kernel}" != "-" ]; then
915915
zdebug "org.zfsbootmenu:kernel set to ${specific_kernel}"
916916
while read -r spec_kexec_args; do
@@ -954,7 +954,7 @@ find_root_prefix() {
954954
zdebug "zfsbe_mnt set to ${zfsbe_mnt}"
955955

956956
# Grab the root prefix from a property if possible
957-
if prefix="$( zfs get -H -o value org.zfsbootmenu:rootprefix "${zfsbe_fs}" )"; then
957+
if prefix="$( zfs get -H -o value org.zfsbootmenu:rootprefix "${zfsbe_fs}" 2>/dev/null )"; then
958958
if [ "${prefix}" != "-" ]; then
959959
zdebug "using org.zfsbootmenu:rootprefix: ${prefix}"
960960
echo "${prefix}"
@@ -1211,7 +1211,7 @@ rewind_checkpoint() {
12111211
checkpoint="${line#checkpoint: }"
12121212
;;
12131213
esac
1214-
done <<<"$( zpool status "${pool}" )"
1214+
done <<<"$( zpool status "${pool}" 2>/dev/null )"
12151215

12161216
[ -z "${checkpoint}" ] && return 1
12171217
tput clear
@@ -1557,7 +1557,7 @@ be_has_encroot() {
15571557

15581558
pool="${fs%%/*}"
15591559

1560-
if [ "$( zpool list -H -o feature@encryption "${pool}" )" != "active" ]; then
1560+
if [ "$( zpool list -H -o feature@encryption "${pool}" 2>/dev/null )" != "active" ]; then
15611561
zdebug "feature@encryption not active on ${pool}"
15621562
echo ""
15631563
return 1
@@ -1591,7 +1591,7 @@ be_is_locked() {
15911591

15921592
if encroot="$( be_has_encroot "${fs}" )"; then
15931593
zdebug "${encroot} discovered as encryption root for ${fs}"
1594-
keystatus="$( zfs get -H -o value keystatus "${encroot}" )"
1594+
keystatus="$( zfs get -H -o value keystatus "${encroot}" 2>&1 )"
15951595
zdebug "${encroot} keystatus: ${keystatus}"
15961596
case "${keystatus}" in
15971597
unavailable)
@@ -1621,7 +1621,7 @@ be_keysource() {
16211621
fi
16221622
zdebug "fs set to ${fs}"
16231623

1624-
if ! keysrc="$( zfs get -H -o value org.zfsbootmenu:keysource "${fs}" )"; then
1624+
if ! keysrc="$( zfs get -H -o value org.zfsbootmenu:keysource "${fs}" 2>/dev/null )"; then
16251625
zwarn "failed to read org.zfsbootmenu:keysource on ${fs}"
16261626
echo ""
16271627
return 1
@@ -1720,7 +1720,7 @@ cache_key() {
17201720
fi
17211721

17221722
relkeyloc=""
1723-
if ksmount="$(zfs get -o value -H mountpoint "${keysrc}" )"; then
1723+
if ksmount="$(zfs get -o value -H mountpoint "${keysrc}" 2>/dev/null )"; then
17241724
case "${ksmount}" in
17251725
none|legacy)
17261726
zdebug "no discernable mountpoint for ${keysrc}, using only absolute key path"
@@ -1817,7 +1817,7 @@ load_key() {
18171817
[ -n "${NO_CACHE}" ] || NO_CACHE=0
18181818

18191819
# If something goes wrong discovering key location, just prompt
1820-
if ! keylocation="$( zfs get -H -o value keylocation "${encroot}" )"; then
1820+
if ! keylocation="$( zfs get -H -o value keylocation "${encroot}" 2>/dev/null )"; then
18211821
zdebug "failed to read keylocation on ${encroot}"
18221822
keylocation="prompt"
18231823
fi
@@ -1866,7 +1866,7 @@ load_key() {
18661866
fi
18671867

18681868
# Otherwise, try to prompt for "passphrase" keys
1869-
keyformat="$( zfs get -H -o value keyformat "${encroot}" )" || keyformat=""
1869+
keyformat="$( zfs get -H -o value keyformat "${encroot}" 2>/dev/null )" || keyformat=""
18701870
if [ "${keyformat}" != "passphrase" ]; then
18711871
zdebug "unable to load key with format ${keyformat} for ${encroot}"
18721872
return 1

0 commit comments

Comments
 (0)