In a follow on post to my previous GUI From an LXC Container on the Host entry, here are some notes on linking sound in an LXC container to the host's sound system.
The primary reason for this was to get around Interactive Broker's broken sound requirements for really old libav libraries. Which is back to the version x53 libraries from the Debian Jessie / Ubuntu Precise 12.04 days. Long story short, I don't have this working yet. The basic issue I have is that, when running TWS in an LXC container, all the configuration menu options but one work. When I click on the 'Sound Manager' menu item, TWS locks up, and I don't see any log messages anywhere as to why this might happen. So there is something special in an LXC container environment which is locking up sound in TWS.
But I did get sound from FireFox / Youtube to work.
This on a Debian Bullseye system.
The basic solution is, in the LXC container configuration file, to mount the Pulse Audio socket from the user's account of the host into the container and set an environment for the user in the container. In this case, the user has UID of 1000:
lxc.mount.entry = /run/user/1000/pulse/native tmp/pulse/native none rw,bind,create=file 0 0
lxc.environment = PULSE_SERVER=unix:/tmp/pulse/native
For completeness, these can be added (helps with ALSA):
lxc.mount.entry = /dev/snd dev/snd none bind,optional,create=dir
lxc.cgroup.devices.allow = c 116:* rwm
That is about all to make it all work. Some or all of the following package installs in the container might help:
sudo apt install \
pulseaudio \
pulseaudio-utils \
pavucontrol \
gstreamer1.0-libav gstreamer1.0-plugins-bad gstreamer1.0-pulseaudio \
mpg123
Setting up LXC on Debian desktop makes mention of "If you don’t want to share PulseAudio socket of your user, you can create additional socket specifically to be used inside containers. On host system execute the following command and then adjust the configuration of containers accordingly:"
$ pactl load-module module-native-protocol-unix socket=/tmp/pulse.socket
I did learn a little about strace to see if I could find the problem (didn't find the problem yet).
# -f traces into a fork, -e with '!' ignores a bunch of syscalls
strace -f -e trace=\!futex,clock_gettime,recvmsg,mprotect,poll Jts/978/tws
I have the following relevant section, which as a (possibly unhandled) haltException, but don't know what it means (forked process):
[pid 3227] lseek(14, 12221947, SEEK_SET) = 12221947
[pid 3227] read(14, "PK\3\4\24\0\10\10\10\0\365a\263P\0\0\0\0\0\0\0\0\0\0\0\0I\0\0\0", 30) = 30
[pid 3227] lseek(14, 12222050, SEEK_SET) = 12222050
[pid 3227] read(14, "\265V\373w\24E\26\376z\246\223&C\33b\220\2701\6A#\16\223\204a\5\5\31\214$1\310"..., 1705) = 1705
[pid 3227] lseek(14, 12224312, SEEK_SET) = 12224312
[pid 3227] read(14, "PK\3\4\24\0\10\10\10\0\365a\263P\0\0\0\0\0\0\0\0\0\0\0\0004\0\0\0", 30) = 30
[pid 3227] lseek(14, 12224394, SEEK_SET) = 12224394
[pid 3227] read(14, "\225S]O\23A\24=\323n\331v[E\253\200\226\"~b?\200\202\324\317\"\202D\223&U\23"..., 770) = 770
[pid 3227] stat("/home/ubuntu/Jts/jts.ini", {st_mode=S_IFREG|0644, st_size=287, ...}) = 0
[pid 3227] openat(AT_FDCWD, "/home/ubuntu/Jts/jts.ini", O_RDONLY) = 73
[pid 3227] fstat(73, {st_mode=S_IFREG|0644, st_size=287, ...}) = 0
[pid 3227] read(73, "[Logon]\r\nuseRemoteSettings=true\r"..., 8192) = 287
[pid 3227] fstat(73, {st_mode=S_IFREG|0644, st_size=287, ...}) = 0
[pid 3227] lseek(73, 0, SEEK_CUR) = 287
[pid 3227] read(73, "", 8192) = 0
[pid 3227] close(73) = 0
[pid 3227] lseek(7, 16689410, SEEK_SET) = 16689410
[pid 3227] read(7, "PK\3\4\n\0\0\10\0\0\351#.Km]\260a2\17\0\0002\17\0\0'\0\0\0", 30) = 30
[pid 3227] lseek(7, 16689479, SEEK_SET) = 16689479
[pid 3227] read(7, "\312\376\272\276\0\0\0004\0\265\10\0\6\10\0\t\10\0 \10\0$\10\0%\1\0\3 : \1"..., 1024) = 1024
[pid 3227] lseek(7, 16690503, SEEK_SET) = 16690503
[pid 3227] read(7, "getType\1\0\rhaltException\1\0\23java/l"..., 2048) = 2048
[pid 3227] lseek(7, 16692551, SEEK_SET) = 16692551
[pid 3227] read(7, "\37\0f\0%\0g\0,\0h\0:\0i\0D\0j\0N\0k\0X\0l\0b\0m\0"..., 818) = 818
[pid 3227] lseek(7, 7380422, SEEK_SET) = 7380422
[pid 3227] read(7, "PK\3\4\n\0\0\10\0\0\350#.K\360u\301\277\362\2\0\0\362\2\0\0+\0\0\0", 30) = 30
[pid 3227] lseek(7, 7380495, SEEK_SET) = 7380495
[pid 3227] read(7, "\312\376\272\276\0\0\0004\0\34\1\0\6\1\0\1J\1\0%com/su"..., 754) = 754
As an update, the above is red-herring, as it happens on a system for which the SoundManager menu item does work.
Some useful sites for networked audio: