fix: Refactor

* fix: Refactor
This commit is contained in:
Kroese 2023-12-28 16:08:12 +01:00 committed by GitHub
parent 19aa313753
commit d09588b915
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 28 deletions

View File

@ -19,35 +19,13 @@ cd /run
trap - ERR trap - ERR
if [[ "$CONSOLE" == [Yy]* ]]; then if [[ "$CONSOLE" == [Yy]* ]]; then
exec qemu-system-x86_64 -pidfile "$QEMU_PID" ${ARGS:+ $ARGS} exec qemu-system-x86_64 ${ARGS:+ $ARGS} && exit $?
exit $?
fi fi
[[ "$DEBUG" == [Yy1]* ]] && info "$VERS" && set -x [[ "$DEBUG" == [Yy1]* ]] && info "$VERS" && set -x
msg=$(qemu-system-x86_64 -daemonize -pidfile "$QEMU_PID" ${ARGS:+ $ARGS}) msg=$(qemu-system-x86_64 -daemonize ${ARGS:+ $ARGS})
{ set +x; } 2>/dev/null
if [[ "$msg" != "char"* || "$msg" != *"serial0)" ]]; then { set +x; } 2>/dev/null && terminal "$msg"
echo "$msg" cat "$QEMU_TERM" 2>/dev/null & wait $! || true
fi
dev="${msg#*/dev/p}" sleep 1 && finish 0
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#*charserial0}"
dev="${dev#*pty:}"
dev="${dev%%$'\n'*}"
dev="${dev%%$'\r'*}"
fi
if [ ! -c "$dev" ]; then
error "Device '$dev' not found!"
finish 34
fi
cat "$dev" 2>/dev/null & wait $! || true
sleep 1
finish 0

View File

@ -7,6 +7,7 @@ API_CMD=6
API_TIMEOUT=50 API_TIMEOUT=50
API_HOST="127.0.0.1:2210" API_HOST="127.0.0.1:2210"
QEMU_TERM=""
QEMU_PORT=7100 QEMU_PORT=7100
QEMU_TIMEOUT=50 QEMU_TIMEOUT=50
QEMU_PID="/run/qemu.pid" QEMU_PID="/run/qemu.pid"
@ -56,6 +57,34 @@ finish() {
exit "$reason" exit "$reason"
} }
terminal() {
local msg=$1
if [[ "${msg,,}" != "char"* || "$msg" != *"serial0)" ]]; then
echo "$msg"
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#*charserial0}"
dev="${dev#*pty:}"
dev="${dev%%$'\n'*}"
dev="${dev%%$'\r'*}"
fi
if [ ! -c "$dev" ]; then
error "Device '$dev' not found!"
finish 34 && return 34
fi
QEMU_TERM="$dev"
return 0
}
_graceful_shutdown() { _graceful_shutdown() {
local code=$? local code=$?
@ -129,4 +158,6 @@ _graceful_shutdown() {
_trap _graceful_shutdown SIGTERM SIGHUP SIGINT SIGABRT SIGQUIT _trap _graceful_shutdown SIGTERM SIGHUP SIGINT SIGABRT SIGQUIT
MON_OPTS="-monitor telnet:localhost:$QEMU_PORT,server,nowait,nodelay" MON_OPTS="\
-pidfile $QEMU_PID \
-monitor telnet:localhost:$QEMU_PORT,server,nowait,nodelay"