#!/bin/bash # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2026 Open-IOV contributors # mission-gz.sh - run INSIDE the guest: bring X up (retry), optionally probe the # GPU GL path (gl_frames), then run GZDoom offscreen with the GLX-pbuffer shim # and the swap-capture shim. Everything logs to /tmp/mission-*.log; completion # is signalled by /tmp/mission-done (content = result line). # # Env knobs: GZ_SECS (default 240) GLF_FRAMES (default 0 = skip probe) # GLF_W/GLF_H GZCAP GZCAP_MAXF GZ_ATTEMPTS (default 2) # # 2026-11-16 (post-reboot c895-c898): the gl_frames probe is now OFF by default # (GLF_FRAMES=0). It is a diagnostic, not a render source, and in the batch it # cost 30-40 s/frame and preceded X/GLX failures that made GZDoom abort with # "Could not create OpenGL window" (rc=255). GZDoom is the mission; probe only # when explicitly requested. set -u export DISPLAY=:0 GZCAP="${GZCAP:-/dev/shm/gzframes.bin}" GZCAP_MAXF="${GZCAP_MAXF:-1800}" GZ_ATTEMPTS="${GZ_ATTEMPTS:-2}" x_up() { local t r for t in 1 2 3 4; do pkill -x Xorg; sleep 1 systemctl reset-failed xorg0 2>/dev/null systemd-run --unit=xorg0 --collect --setenv=HOME=/root \ /usr/bin/Xorg :0 -config /etc/X11/xorg.conf >/dev/null 2>&1 sleep 7 if timeout 12 xdpyinfo >/dev/null 2>&1; then echo "$t"; return 0; fi echo "x try $t: dead" done return 1 } echo "mission start $(date +%T)" rm -f /tmp/mission-done /tmp/gzframes.bin "$GZCAP" mkdir -p /tmp/gzshots # 1. X up (the DDX ScreenInit is a per-start lottery) XOK=0 XTRY=$(x_up) && XOK=1 echo "XOK try=$XTRY $(date +%T)" if [ "$XOK" = 0 ]; then echo "X-FAIL" > /tmp/mission-done; exit 1; fi bash /tmp/guest_mode.sh 2>/dev/null || true # 2. Optional GPU GL probe (diagnostic only; off by default) GLF_FRAMES="${GLF_FRAMES:-0}" if [ "$GLF_FRAMES" != 0 ]; then ( timeout -k 5 120 /tmp/gl_frames "$GLF_FRAMES" "${GLF_W:-320}" "${GLF_H:-240}" 5 \ > /tmp/mission-gl.log 2>&1 echo "glf rc=$? $(date +%T)" >> /tmp/mission-gl.log ) & GLFPID=$! sleep 10 echo "x alive after glf start: $(pgrep -c Xorg)" wait $GLFPID 2>/dev/null grep -E "^FRAME seq" /tmp/mission-gl.log | tail -3 else : > /tmp/mission-gl.log echo "glf skipped (GLF_FRAMES=0)" fi # 3. GZDoom offscreen + pbuffer shim + swap capture. The run is DETACHED and # bounded by GZ_SECS: a GPU wait must never wedge this shell (c899: glFinish # on non-retiring work put gzdoom in an uninterruptible nv ioctl and even # SIGKILL could not reap it, so the mission never wrote mission-done). GZ_SECS="${GZ_SECS:-240}" export GZ_RCFILE=/tmp/gz-rc GZRC=255 attempt=1 while [ "$attempt" -le "$GZ_ATTEMPTS" ]; do if ! pgrep -x Xorg >/dev/null; then echo "X dead before GZDoom attempt $attempt - restarting" >> /tmp/mission-gz.log x_up >/dev/null 2>&1 || { echo "X restart failed" >> /tmp/mission-gz.log; break; } fi rm -f "$GZ_RCFILE" GZ_DETACH=1 TIMEOUT="$GZ_SECS" GZLOG=/tmp/mission-gz.log GZCAP="$GZCAP" \ GZCAP_MAXF="$GZCAP_MAXF" \ GZPBUF_W="${GZPBUF_W:-640}" GZPBUF_H="${GZPBUF_H:-480}" \ bash /tmp/gzdoom_pbuf_run.sh GZRC="hung" for i in $(seq 1 $((GZ_SECS + 30))); do if [ -f "$GZ_RCFILE" ]; then GZRC=$(cat "$GZ_RCFILE"); break; fi sleep 1 done echo "gz attempt=$attempt rc=$GZRC $(date +%T)" >> /tmp/mission-gz.log # Stop the renderer before fetching/next attempt. A D-state process # survives SIGKILL; that is fine, the capture file is append-only and the # cycle teardown removes it. pkill -x gzdoom 2>/dev/null sleep 1 pkill -9 -x gzdoom 2>/dev/null [ "$GZRC" != 255 ] && break attempt=$((attempt + 1)) sleep 2 done ls -la "$GZCAP" /tmp/gzshots 2>&1 | tail -5 echo "XORG-ALIVE=$(pgrep -c Xorg)" | tee -a /tmp/mission-gz.log echo "DONE x=$XOK gzrc=$GZRC $(date +%T)" > /tmp/mission-done echo "mission end $(date +%T)"