Review fixes: tolerate a vanished default sink, recover stale virtual displays

- virtual_audio: when the previous default output no longer exists, still
  unload the null sink instead of keeping all output on it.
- uu-virtual-desktop: a socket/lock left by a dead Xvfb no longer blocks the
  service forever (Restart=always loop); a live owner is still refused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
VallierDevandClaude Opus 5.5 committed 2026-10-15 11:03:42 +08:00
1 parent 0da79a45eb
commit 9125e51350
2 files changed
+14 -2

No files matched your search

+9 -1
View File
@@ -26,7 +26,15 @@ case "$display" in :[0-9]*) ;; *) echo "UU_VIRTUAL_DISPLAY must be a local displ
number="${display#:}"
case "$number" in *[!0-9]*|'') echo "invalid display number" >&2; exit 1 ;; esac
socket="/tmp/.X11-unix/X$number"
[ ! -e "$socket" ] || { echo "display already in use" >&2; exit 1; }
# A live server owns the display; a dead one's leftovers (killed Xvfb) are cleaned up by Xvfb itself.
lock="/tmp/.X$number-lock"
if [ -e "$socket" ] || [ -e "$lock" ]; then
owner=$(tr -d ' \n' < "$lock" 2>/dev/null || :)
case "$owner" in ''|*[!0-9]*) owner= ;; esac
if [ -z "$owner" ] || kill -0 "$owner" 2>/dev/null; then echo "display already in use" >&2; exit 1; fi
echo "removing stale display $display left by dead process $owner" >&2
rm -f "$lock" "$socket" 2>/dev/null || { echo "cannot remove stale display files" >&2; exit 1; }
fi
umask 077
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
authority="$XDG_RUNTIME_DIR/uu-virtual-$number.Xauthority"
+5 -1
View File
@@ -49,7 +49,11 @@ fn persist(route: &Route) -> Result<(), ()> {
}
fn recover(route: &Route) -> Result<(), ()> {
// Do not overwrite a default explicitly changed by the user during remote control.
if pactl(&["get-default-sink"])? == SINK { pactl(&["set-default-sink",&route.previous])?; }
// The previous output may be gone (unplugged USB card): still unload our sink so the server
// picks another default instead of leaving every stream on a null sink.
if pactl(&["get-default-sink"]).is_ok_and(|s| s == SINK) && pactl(&["set-default-sink",&route.previous]).is_err() {
log::warn!("Previous default audio output unavailable; the sound server will choose a new default");
}
move_inputs(SINK,&route.previous);
let modules=owned_modules(&pactl(&["list","short","modules"])?);
for id in modules { pactl(&["unload-module",&id.to_string()])?; }