Detach emulators from launching shell

This commit is contained in:
iris committed 2026-09-10 02:25:45 -04:00
1 parent 80d8324b4f
commit 9a0364ad19
2 files changed
+25 -6

No files matched your search

+19 -6
View File
@@ -193,6 +193,20 @@ headless_display() {
cat "$run/display"
}
# Starts the emulator outside the caller's terminal session.
#
# A plain background job survives an ordinary interactive shell here, which hid this until `emu up`
# was run through an isolated command runner: the emulator reached boot, `emu up` returned success,
# and the runner then closed its session and asked every job still attached to it to shut down. The
# emulator complied cleanly, so its log ended at "Boot completed" and looked like a device crash.
# `setsid` is the process-lifetime boundary; `nohup`, a closed stdin and disown cover the shell's
# own three ways of retaining or signalling the job. Keep every rendering branch on this path.
start_emulator() {
setsid nohup "$@" </dev/null >"$log" 2>&1 &
pid=$!
disown -h "$pid"
}
cmd_up() {
if serial=$(avd_serial "$adb" "$avd"); then
echo "emu: '$avd' is already running ($serial)" >&2
@@ -245,21 +259,20 @@ cmd_up() {
# Vulkan that gfxstream cannot pair with Venus here.
if [ "${EMU_GPU:-}" != software ] && { [ -n "${DISPLAY:-}" ] || [ -n "${WAYLAND_DISPLAY:-}" ]; }; then
echo "emu: starting '$avd' with GPU acceleration" >&2
"$sdk/emulator/emulator" -avd "$avd" -gpu host -no-audio >"$log" 2>&1 &
start_emulator "$sdk/emulator/emulator" -avd "$avd" -gpu host -no-audio
elif [ "${EMU_GPU:-}" != software ] && display=$(headless_display); then
echo "emu: no display -- starting '$avd' headless on the GPU ($display)" >&2
DISPLAY="$display" "$sdk/emulator/emulator" -avd "$avd" \
-gpu host $GPU_HOST_FEATURES -no-audio -no-window >"$log" 2>&1 &
start_emulator env DISPLAY="$display" "$sdk/emulator/emulator" -avd "$avd" \
-gpu host $GPU_HOST_FEATURES -no-audio -no-window
else
if [ "${EMU_GPU:-}" = software ]; then
echo "emu: EMU_GPU=software -- starting '$avd' on the CPU, off the host GPU" >&2
else
echo "emu: no display and no compositor -- starting '$avd' on software rendering" >&2
fi
"$sdk/emulator/emulator" -avd "$avd" -gpu swiftshader_indirect -no-audio -no-window \
>"$log" 2>&1 &
start_emulator "$sdk/emulator/emulator" -avd "$avd" -gpu swiftshader_indirect \
-no-audio -no-window
fi
pid=$!
for _ in $(seq 150); do
if ! kill -0 "$pid" 2>/dev/null; then