Skip to content

Commit

Permalink
b_dom0_getQvmBlockInfo: set a non-zero exit code on empty return valu…
Browse files Browse the repository at this point in the history
…es as well
  • Loading branch information
3hhh committed Jul 6, 2024
1 parent c44bddc commit 4abcee4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions lib/os/qubes4/dom0
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ echo "${ret/declare -A ret/declare -A $outVar}"
#+[retrieve field]: Name of the field to retrieve.
#+[filter field i]: Name of any field supported by [b_dom0_parseQvmBlock](#b_dom0_parseQvmBlock).
#+[filter value i]: The value to search for in \[filter field i\] (equality check).
#+returns: The value of the requested field and sets a zero exit code on success. Sets a non-zero exit code if no matching value could be found. On errors [B_E](#B_E) is called.
#+returns: The value of the requested field and sets a zero exit code on success. Sets a non-zero exit code if no matching value could be found or the found value was empty. On errors [B_E](#B_E) is called.
#+@B_E
function b_dom0_getQvmBlockInfo {
local blockinfo="$1"
Expand Down Expand Up @@ -1007,8 +1007,10 @@ for ((i=0; i < ${blockinfo["max"]}; i++)) ; do
#return matching entry
if [ $matching -eq 0 ] ; then
if [ "${blockinfo["${i}_$retField"]+exists}" ] ; then
echo "${blockinfo["${i}_$retField"]}"
return 0
local ret="${blockinfo["${i}_$retField"]}"
echo "$ret"
[ -n "$ret" ] #return value
return
else
B_ERR="Requested a non-existing field $retField."
B_E
Expand Down
4 changes: 2 additions & 2 deletions tests/os/qubes4/dom0.bats
Original file line number Diff line number Diff line change
Expand Up @@ -827,11 +827,11 @@ test2:dm-0 desc with spaces '
[[ "$output" == "()" ]]

runSL b_dom0_getQvmBlockInfo "$test1ExpectedSpec" "used by" "backend" "sys-usb" "device id" "mmcblk0"
[ $status -eq 0 ]
[ $status -ne 0 ]
[ -z "$output" ]

runSL b_dom0_getQvmBlockInfo "$test1ExpectedSpec" "frontend-dev" "backend" "sys-usb" "device id" "mmcblk0"
[ $status -eq 0 ]
[ $status -ne 0 ]
[ -z "$output" ]

runSL b_dom0_getQvmBlockInfo "$test1ExpectedSpec" "frontend-dev" "backend" "sys-nonexisting" "device id" "mmcblk0"
Expand Down

0 comments on commit 4abcee4

Please sign in to comment.