fix: Display QEMU output (#558)

This commit is contained in:
Kroese 2024-01-13 18:16:17 +01:00 committed by GitHub
parent a3d6e3740c
commit 3a507f5bf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 19 deletions

View File

@ -83,7 +83,7 @@ isCow() {
if [[ "${FS,,}" == "xfs" || "${FS,,}" == "zfs" || "${FS,,}" == "btrfs" || "${FS,,}" == "bcachefs" ]]; then
return 0
fi
return 1
}
@ -126,7 +126,7 @@ createDisk() {
fi
if [[ "$ALLOCATE" == [Nn]* ]]; then
# Create an empty file
if ! truncate -s "$DATA_SIZE" "$DISK_FILE"; then
rm -f "$DISK_FILE"

View File

@ -22,11 +22,12 @@ if [[ "$CONSOLE" == [Yy]* ]]; then
exec qemu-system-x86_64 ${ARGS:+ $ARGS}
fi
[[ "$DEBUG" == [Yy1]* ]] && info "$VERS" && set -x
msg=$(qemu-system-x86_64 ${ARGS:+ $ARGS})
[[ "$DEBUG" == [Yy1]* ]] && info "$VERS" && echo "Arguments: $ARGS" && echo
{ qemu-system-x86_64 ${ARGS:+ $ARGS} >"$QEMU_OUT" 2>"$QEMU_LOG"; rc=$?; } || :
(( rc != 0 )) && error "$(cat "$QEMU_LOG")" && exit 15
{ set +x; } 2>/dev/null && terminal "$msg"
terminal
tail -fn +0 "$QEMU_LOG" 2>/dev/null &
cat "$QEMU_TERM" 2>/dev/null & wait $! || true
cat "$QEMU_TERM" 2>/dev/null & wait $! || :
sleep 1 && finish 0

View File

@ -12,6 +12,7 @@ QEMU_PORT=7100
QEMU_TIMEOUT=50
QEMU_PID="/run/qemu.pid"
QEMU_LOG="/run/qemu.log"
QEMU_OUT="/run/qemu.out"
QEMU_END="/run/qemu.end"
if [[ "$KVM" == [Nn]* ]]; then
@ -19,9 +20,6 @@ if [[ "$KVM" == [Nn]* ]]; then
QEMU_TIMEOUT=$(( QEMU_TIMEOUT*2 ))
fi
rm -f "$QEMU_PID"
rm -f "$QEMU_LOG"
rm -f "$QEMU_END"
touch "$QEMU_LOG"
_trap() {
@ -62,15 +60,25 @@ finish() {
terminal() {
local msg=$1
local dev=""
if [[ "${msg,,}" != "char"* || "$msg" != *"serial0)" ]]; then
echo "$msg"
if [ -f "$QEMU_OUT" ]; then
local msg
msg="$(cat "$QEMU_OUT")"
if [ -n "$msg" ]; then
if [[ "${msg,,}" != "char"* || "$msg" != *"serial0)" ]]; then
echo "$msg"
fi
dev="${msg#*/dev/p}"
dev="/dev/p${dev%% *}"
fi
fi
local dev="${msg#*/dev/p}"
dev="/dev/p${dev%% *}"
if [ ! -c "$dev" ]; then
dev=$(echo 'info chardev' | nc -q 1 -w 1 localhost "$QEMU_PORT" | tr -d '\000')
dev="${dev#*serial0}"

View File

@ -36,10 +36,7 @@ STORAGE="/storage"
# Cleanup files
rm -f /run/dsm.url
rm -f /run/qemu.ip
rm -f /run/qemu.log
rm -f /run/qemu.pid
rm -f /run/qemu.end
rm -f /run/qemu.*
# Cleanup dirs