Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/66'
Browse files Browse the repository at this point in the history
* origin/pr/66:
  Improve load of modules for dynamic switch
  init: support core-admin not setting -qubes-audio
  Unload module vchan if no domid is provided
  init: support for not loading vchan-sink
  pulseaudio: add null and always modules
  Support setting audiovm not being dom0 on start
  pulseaudio: add pactl inside rootfs
  • Loading branch information
marmarek committed May 12, 2024
2 parents cc82a9a + 666c0ca commit 06d5868
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 12 deletions.
18 changes: 12 additions & 6 deletions pulseaudio/patches/pulseaudio-minimal-vchan-sink.patch
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
--- a/src/Makefile.am 2019-12-16 10:08:27.000000000 +0300
+++ b/src/Makefile.am 2020-05-27 16:19:57.109458668 +0300
@@ -2301,3 +2301,15 @@ coverage:
diff --git a/src/Makefile.am b/src/Makefile.am
index 454b644bb..c63308790 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2312,3 +2312,19 @@ coverage:
endif

.PHONY: massif update-all update-ffmpeg update-map-file coverage
+
+# vchan sink module
+module_vchan_sink_la_SOURCES = modules/module-vchan-sink.c
+module_vchan_sink_la_LDFLAGS = $(MODULE_LDFLAGS) -lvchan-xen
+module_vchan_sink_la_LDFLAGS = $(MODULE_LDFLAGS) -lvchan-xen
+module_vchan_sink_la_LIBADD = $(MODULE_LIBADD)
+module_vchan_sink_la_CFLAGS = $(AM_CFLAGS) -I/usr/include/vchan-xen -DPA_MODULE_NAME=module_vchan_sink -Dfoomodulepipecustomsymdeffoo
+
+modlibexec_LTLIBRARIES = libprotocol-native.la \
+ module-native-protocol-unix.la \
+ module-vchan-sink.la
+ module-null-sink.la \
+ module-null-source.la \
+ module-always-sink.la \
+ module-always-source.la \
+ module-vchan-sink.la
+bin_PROGRAMS = pulseaudio pacat pactl
+lib_LTLIBRARIES = libpulse.la
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
29 changes: 24 additions & 5 deletions rootfs/init
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,25 @@ 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
# Extract audiovm parameter and remove them from dm_args
audio_args=$(echo "$dm_args" | sed -n '/^-qubes-audio:/p')
dm_args=$(echo "$dm_args" | sed '/^-qubes-audio:/d')
# We support core-admin not setting -qubes-audio option
if [ -z "$audio_args" ]; then
domid=0
else
domid="$(echo "$audio_args" | sed -n 's/^.*[:,]audiovm_xid=\([^,]\+\).*$/\1/p')"
fi

# 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 @@ -38,9 +48,18 @@ if [ -n "$audio_model" ] ; then
fi
export XDG_CONFIG_HOME='/tmp'
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-vchan-sink domid=0" &
if [ "$domid" -ge 0 ]; then
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-vchan-sink domid=$domid" &
else
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" &
fi
fi

# Extract network parameters and remove them from dm_args
Expand Down
19 changes: 19 additions & 0 deletions rootfs/qubes.SetAudioVM
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

set -e

# Default to dom0 if called with empty arg
domid="${1:-0}"

export PULSE_SERVER=unix:/tmp/pa.sock

for module in module-always-sink module-always-source module-null-sink module-null-source; do
pactl load-module $module || true
done
pactl unload-module module-vchan-sink

if [ "$domid" -ge 0 ]; then
pactl load-module module-vchan-sink domid="$domid"
pactl set-default-sink vchan_output
pactl set-default-source vchan_input
fi
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 06d5868

Please sign in to comment.