Skip to content

Commit

Permalink
Use bash's read to parse qubesd response
Browse files Browse the repository at this point in the history
This is faster and less error-prone than relying on external programs.
  • Loading branch information
DemiMarie committed Dec 20, 2022
1 parent 124425c commit 56638f0
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions qubes-rpc/admin.vm.volume.Import
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,29 @@ if [[ "${0##*/}" == admin.vm.volume.ImportWithSize ]]; then
fi
fi

echo -n "$requested_size" | qubesd-query -c /var/run/qubesd.internal.sock \
"$QREXEC_REMOTE_DOMAIN" \
"internal.vm.volume.ImportBegin" \
"$QREXEC_REQUESTED_TARGET" \
"$1" >"$tmpfile"
{
echo -n "$requested_size" | qubesd-query -c /var/run/qubesd.internal.sock \
"$QREXEC_REMOTE_DOMAIN" \
"internal.vm.volume.ImportBegin" \
"$QREXEC_REQUESTED_TARGET" \
"$1"
printf \\0
} >"$tmpfile"

# exit if qubesd returned an error (not '0\0')
if [ "$(head -c 2 "$tmpfile" | hexdump -e '/1 "%02x"')" != "3000" ]; then
cat "$tmpfile"
exit 1
fi
size=$(tail -c +3 "$tmpfile"|cut -d ' ' -f 1)
path=$(tail -c +3 "$tmpfile"|cut -d ' ' -f 2)
{
# Read response from qubesd
read -r -d '' first

# exit if qubesd returned an error (not '0\0')
if [[ "$first" != '0' ]]; then
head -c-1 -- "$tmpfile"
exit 1
fi

# Finish reading response
read -r -d ' ' size
read -r -d '' path
} < "$tmpfile"

error=""

Expand Down

0 comments on commit 56638f0

Please sign in to comment.