#!/usr/bin/env bash
shopt -s lastpipe
set -euE -o pipefail

source "/etc/conf.d/qemu.d/$1"
args+=(
	-name "$1",debug-threads=on
	-pidfile "/run/qemu-$1/pid"
	-vnc     unix:"/run/qemu-$1/vnc.sock"
	-monitor unix:"/run/qemu-$1/monitor.sock",server,nowait
	-serial  file:"/dev/stdout"
	-daemonize
)
{
	qemu-system-"${system}" "${args[@]}"
	systemd-notify --ready
} | exec cat