Skip to content

Commit

Permalink
pulseaudio: add pactl inside rootfs
Browse files Browse the repository at this point in the history
  • Loading branch information
fepitre committed May 3, 2024
1 parent e13539e commit f19ca08
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
9 changes: 8 additions & 1 deletion rootfs/gen
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ if [[ -e "$PWD/build/qrexec/agent/qrexec-agent" ]]; then
export LD_LIBRARY_PATH="$PWD/build/padist/lib:$PWD/build/padist/lib/pulseaudio:$PWD/build/qrexec/libqrexec"
fi
inst build/padist/usr/local/bin/pulseaudio /bin/pulseaudio
inst build/padist/usr/local/bin/pactl /bin/pactl
for mod in build/padist/lib/module-*.so; do
inst "$mod" "/lib/$(basename "$mod")"
done
Expand All @@ -88,7 +89,7 @@ inst build/qrexec/agent/qrexec-agent /bin/qrexec-agent
inst build/qrexec/agent/qrexec-client-vm /bin/qrexec-client-vm
inst build/qrexec/agent/qrexec-fork-server /bin/qrexec-fork-server
echo "root:x:0:0:root:/root:/bin/sh" > "$rootfs_dir"/etc/passwd
echo "bus/usb/00[1-9]/00[2-9] 0:0 660 *sh /bin/qusb.sh" > "$rootfs_dir"/etc/mdev.conf
echo "bus/usb/00[1-9]/00[2-9] 0:0 660 *sh /bin/qusb.sh" > "$rootfs_dir"/etc/mdev.conf
fi

for i in write watch rm ls list; do
Expand All @@ -107,6 +108,12 @@ inst "rootfs/qemu-ifup" "/etc/qemu-ifup"
inst "rootfs/qemu-ifdown" "/etc/qemu-ifdown"
inst "rootfs/init" "/init"

mkdir -p "$rootfs_dir"/etc/qubes-rpc
inst "rootfs/qubes.SetAudioVM" /etc/qubes-rpc/qubes.SetAudioVM

### Uncomment only for development
#inst "rootfs/qubes.VMShell" /etc/qubes-rpc/qubes.VMShell

mkdir "$rootfs_dir"/lib.new
(find "$rootfs_dir"/{,usr/,usr/local/}lib{,64} -type f -print0 || true) | xargs -0r mv -t "$rootfs_dir"/lib.new/
rm -rf "${rootfs_dir:?}"/{,usr/,usr/local/}lib{,64}
Expand Down
8 changes: 6 additions & 2 deletions rootfs/init
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ vm_path=$(xenstore-read "/local/domain/$domid/vm")
dm_args=$(xenstore-read $(xenstore-list -p "$vm_path/image/dm-argv"|sort))

usb_args=
if test -e /bin/qrexec-agent; then
if test -e /bin/qrexec-agent; then
usb_args=$'-device\nnec-usb-xhci,id=xhci'
mkdir -p /var/run/qubes
USER=root qrexec-agent &
touch /dev/mdev.log
mdev -d
fi

# add audiodev conf to cmdline and run pulseaudio
# add audiodev conf to cmdline and run pulseaudio
audio_model=$(echo "$dm_args" | sed -n '/^\(intel-hda\|ac97\|adlib\|es1370\|cs4231a\|gus\|sb16\)$/ {p}')
if [ -n "$audio_model" ] ; then
model_args=
Expand All @@ -40,6 +40,10 @@ if [ -n "$audio_model" ] ; then
pa_args=$'-audiodev\npa,id=qemupa,server=unix:/tmp/pa.sock'$model_args;
pulseaudio --use-pid-file=no --daemonize=no --exit-idle-time=-1 -n \
-L "module-native-protocol-unix auth-anonymous=1 socket=/tmp/pa.sock" \
-L "module-always-sink" \
-L "module-always-source" \
-L "module-null-sink" \
-L "module-null-source" \
-L "module-vchan-sink domid=0" &
fi

Expand Down
14 changes: 14 additions & 0 deletions rootfs/qubes.SetAudioVM
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

set -e

# Default to dom0
domid="${1:-0}"

export PULSE_SERVER=unix:/tmp/pa.sock

pactl unload-module module-vchan-sink
pactl load-module module-vchan-sink domid="$domid"

pactl set-default-sink vchan_output
pactl set-default-source vchan_input
2 changes: 2 additions & 0 deletions rootfs/qubes.VMShell
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec /bin/sh

0 comments on commit f19ca08

Please sign in to comment.