From 3a507f5bf6a3d0d1b467c93fcbf5d4b5b031c1b8 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 13 Jan 2024 18:16:17 +0100 Subject: [PATCH] fix: Display QEMU output (#558) --- src/disk.sh | 4 ++-- src/entry.sh | 9 +++++---- src/power.sh | 26 +++++++++++++++++--------- src/reset.sh | 5 +---- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/disk.sh b/src/disk.sh index 0c40089..0493963 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -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" diff --git a/src/entry.sh b/src/entry.sh index a95d82a..015c00a 100755 --- a/src/entry.sh +++ b/src/entry.sh @@ -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 diff --git a/src/power.sh b/src/power.sh index 09def3b..0b62775 100644 --- a/src/power.sh +++ b/src/power.sh @@ -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}" diff --git a/src/reset.sh b/src/reset.sh index 6aadbea..200b9b7 100644 --- a/src/reset.sh +++ b/src/reset.sh @@ -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