netbrain / zwift

Easily zwift on linux
The Unlicense
288 stars 32 forks source link

pulseaudio doesn't work after running zwift #100

Closed perrin4869 closed 7 months ago

perrin4869 commented 7 months ago

Describe the bug Due to #94, after running zwift, pulseaudio will fail with a message:

$ pamixer
Failed to create secure directory (/run/user/1000/pulse): Permission denied
Connection error

Looking at the directory, I find:

 $ ls -lah /run/user/1000
total 4.0K
drwx------ 17 perrin4869 users  500 Apr 25 22:25 .
drwxr-xr-x  3 root       root    60 Apr 25 12:48 ..
drwx------  2 perrin4869 users   60 Apr 25 12:48 at-spi
drwx------  6 perrin4869 users  120 Apr 25 17:37 containers
drwx------  3 perrin4869 users   60 Apr 25 12:48 dbus-1
drwx------  2 perrin4869 users   60 Apr 25 12:48 dconf
dr-x------  2 perrin4869 users    0 Jan  1  1970 doc
drwx------  2 perrin4869 users  140 Apr 25 12:50 gnupg
dr-x------  2 perrin4869 users    0 Apr 25 12:48 gvfs
drwx------  2 perrin4869 users   40 Apr 25 17:17 gvfsd
drwx------  2 perrin4869 users  100 Apr 25 12:48 i3
drwx------  2 perrin4869 root    60 Apr 25 22:25 keyring
drwx-----T  3 perrin4869 users   60 Apr 25 17:37 libpod
drwx--x--x  2 perrin4869 users   60 Apr 25 19:26 netns
srwxr-xr-x  1 perrin4869 users    0 Apr 25 17:18 nvim.17872.0
srwxr-xr-x  1 perrin4869 users    0 Apr 25 14:14 nvim.24940.0
srwxr-xr-x  1 perrin4869 users    0 Apr 25 12:50 nvim.6123.0
srwxr-xr-x  1 perrin4869 users    0 Apr 25 12:48 pipewire-0
srwxr-xr-x  1 perrin4869 users    0 Apr 25 12:48 pipewire-0-manager
-rw-r-----  1 perrin4869 users    0 Apr 25 12:48 pipewire-0-manager.lock
-rw-r-----  1 perrin4869 users    0 Apr 25 12:48 pipewire-0.lock
drwx------  2     100999 100099  80 Apr 25 12:48 pulse
-rw-------  1 perrin4869 users    5 Apr 25 22:24 rofi.pid
drwx-----T  2 perrin4869 users   40 Apr 25 19:26 runc
drwx------  2 perrin4869 users  260 Apr 25 22:25 wezterm

Running sudo chown perrin4869:users /run/user/1000/pulse restores pulseaudio.

hobeone commented 7 months ago

Where do you see the error? I don't think we try to run pamixer anywhere in the container

perrin4869 commented 7 months ago

Oh, pamixer is just an example of what happens when a program tries to access pulseaudio after the zwift container is run, and it's the way I found the cause of the problem :) But any program trying to play audio will fail until the permissions are fixed I'm thinking that it might be a good idea for podman to go back to using --userns? Isn't this kind of issues that that option tries to prevent?

hobeone commented 7 months ago

It did but just for podman. With the update from #94 we should be setting UID & GID in a way that works for both podman and docker. Could you paste the output you see when running zwift.sh in a console?

perrin4869 commented 7 months ago

Sure!

./zwift.sh
+ IMAGE=docker.io/netbrain/zwift
+ VERSION=latest
+ [[ ! -n '' ]]
++ command -v podman
+ [[ -x /usr/bin/podman ]]
+ CONTAINER_TOOL=podman
+ [[ -f /proc/driver/nvidia/version ]]
+ VGA_DEVICE_FLAG='--device /dev/dri:/dev/dri'
+ NETWORKING=bridge
++ id -u
+ ZWIFT_UID=1000
++ id -g
+ ZWIFT_GID=100
+ [[ -f /home/perrin4869/.config/zwift/config ]]
+ [[ -f /home/perrin4869/.config/zwift/perrin4869-config ]]
+ [[ ! -n '' ]]
++ curl -s https://raw.githubusercontent.com/netbrain/zwift/master/zwift.sh
++ sha256sum
++ awk '{print $1}'
+ REMOTE_SUM=5837a9d6dd59bd36f5122fb827be3949dee3603b45608b39a8ff27417561245a
++ sha256sum ./zwift.sh
++ awk '{print $1}'
+ THIS_SUM=5837a9d6dd59bd36f5122fb827be3949dee3603b45608b39a8ff27417561245a
+ '[' 5837a9d6dd59bd36f5122fb827be3949dee3603b45608b39a8ff27417561245a = 5837a9d6dd59bd36f5122fb827be3949dee3603b45608b39a8ff27417561245a ']'
+ echo 'You are running latest zwift.sh 👏'
You are running latest zwift.sh 👏
+ [[ ! -n '' ]]
+ podman pull docker.io/netbrain/zwift:latest
Trying to pull docker.io/netbrain/zwift:latest...
Getting image source signatures
Copying blob bc0b3fb127a1 skipped: already exists
Copying blob b66b40a74fed skipped: already exists
Copying blob ce41c08c4890 skipped: already exists
Copying blob 46853dcfe905 skipped: already exists
Copying blob d0f2486d25ef skipped: already exists
Copying blob 6a11eb1f8b47 skipped: already exists
Copying blob 856c7da60705 skipped: already exists
Copying blob 1ef408996790 skipped: already exists
Copying blob 9d31c3788708 skipped: already exists
Copying blob f35d682d70a5 skipped: already exists
Copying blob 13cab8f33aa8 skipped: already exists
Copying blob ea0c034005db skipped: already exists
Copying blob 1e020ab362d5 skipped: already exists
Copying blob 85cdda014776 skipped: already exists
Copying blob 4f4fb700ef54 skipped: already exists
Copying blob 8304d795d90c skipped: already exists
Copying blob 4f4fb700ef54 skipped: already exists
Copying blob 071ecb8e971d skipped: already exists
Copying blob 4f4fb700ef54 skipped: already exists
Copying blob c58832b72e80 skipped: already exists
Copying blob 4f4fb700ef54 skipped: already exists
Copying blob 4066b79e3930 skipped: already exists
Copying blob cb282060bc56 skipped: already exists
Copying config 38c46bfce7 done   |
Writing manifest to image destination
38c46bfce73df336a430af4edb4e2b1993d82fa7e76b7e674b02be986db9faf4
++ podman run -d --rm --privileged --network bridge --name zwift-perrin4869 -e DISPLAY=:0 -e ZWIFT_UID=1000 -e ZWIFT_GID=100 -v /tmp/.X11-unix:/tmp/.X11-unix -v /run/user/1000/pulse:/run/user/1000/pulse -v zwift-perrin4869:/home/user/.wine/drive_c/users/user/Documents/Zwift --device /dev/dri:/dev/dri docker.io/netbrain/zwift:latest
+ CONTAINER=e0e6057abe3069167a869aabdcdc52371667a1c5c41b1bdc8ac22c8f1e328646
+ [[ -z '' ]]
++ podman inspect '--format={{ .Config.Hostname  }}' e0e6057abe3069167a869aabdcdc52371667a1c5c41b1bdc8ac22c8f1e328646
+ xhost +local:e0e6057abe30
non-network local connections being added to access control list
perrin4869 commented 7 months ago

sorry for not being more helpful in troubleshooting, I am kinda swamped right now and wanted to at least report the issue :)

hobeone commented 7 months ago

Thanks, two more things: Can you post the logs from inside the container? Whatever the equivalent of docker logs -f zwift-perrin4869 is and ls -al /run/user/1000/pulse

perrin4869 commented 7 months ago
$ podman logs -f zwift-perrin4869
++ id -u user
+ USER_UID=1000
++ id -g user
+ USER_GID=1000
+ '[' -n 1000 ']'
+ '[' 1000 -eq 1000 ']'
+ USER_UID=1000
+ '[' -n 100 ']'
+ '[' 100 -eq 100 ']'
+ USER_GID=100
+ usermod -o -u 1000 user
usermod: no changes
+ groupmod -o -g 100 user
+ chown -R 1000:100 /home/user
+ mkdir -p /run/user/1000
+ chown -R user:user /run/user/1000
+ sed -i s/1000/1000/g /etc/pulse/client.conf
+ gosu user:user /bin/setup_and_run_zwift
+ ZWIFT_HOME='/home/user/.wine/drive_c/Program Files (x86)/Zwift'
+ mkdir -p '/home/user/.wine/drive_c/Program Files (x86)/Zwift'
+ cd '/home/user/.wine/drive_c/Program Files (x86)/Zwift'
+ '[' '' = update ']'
++ ls -A .
+ '[' '!' 'ANT_DLL.dll
APR2007_xinput_x64.cab
APR2007_xinput_x86.cab
BleWin10Lib.dll
BleWin10Lib_V2.dll
CloseLauncher.exe
DSETUP.dll
DXSETUP.exe
Feb2010_X3DAudio_x64.cab
Feb2010_X3DAudio_x86.cab
Jun2010_XAudio_x64.cab
Jun2010_XAudio_x86.cab
Launcher_ver_cur.xml
Patcher.dll
VC_redist.x64.exe
WebView2Loader.dll
Webview2Setup.exe
Windows ANT Dongle Driver
ZwiftApp.exe
ZwiftHelper.exe
ZwiftLauncher.exe
ZwiftLauncher.exe.config
ZwiftWindowsCrashHandler.exe
Zwift_1.0.128453_fd976f3b_manifest.xml
Zwift_ver_cur.xml
Zwift_ver_cur_filename.txt
assets
bink2w64.dll
data
dotnet-v4.7.2-installer.exe
dsetup32.dll
dxupdate.cab
unins000.dat
unins000.exe' ']'
+ [[ ! -z '' ]]
+ echo 'starting zwift...'
starting zwift...
+ wine start ZwiftLauncher.exe SilentLaunch
preloader: Warning: failed to reserve range 00010000-00110000
preloader: Warning: failed to reserve range 0000000000010000-0000000000110000
preloader: Warning: failed to reserve range 0000000000010000-0000000000110000
preloader: Warning: failed to reserve range 0000000000010000-0000000000110000
preloader: Warning: failed to reserve range 0000000000010000-0000000000110000
preloader: Warning: failed to reserve range 00010000-00110000
preloader: Warning: failed to reserve range 0000000000010000-0000000000110000
preloader: Warning: failed to reserve range 00010000-00110000
preloader: Warning: failed to reserve range 0000000000010000-0000000000110000
preloader: Warning: failed to reserve range 0000000000010000-0000000000110000
preloader: Warning: failed to reserve range 0000000000010000-0000000000110000
preloader: Warning: failed to reserve range 0000000000010000-0000000000110000
preloader: Warning: failed to reserve range 0000000000010000-0000000000110000
preloader: Warning: failed to reserve range 00010000-00110000
preloader: Warning: failed to reserve range 0000000000010000-0000000000110000
++ winedbg --command 'info proc'
++ grep -P ZwiftLauncher.exe
++ grep -oP '^\s\K.+?(?=\s)'
preloader: Warning: failed to reserve range 00010000-00110000
preloader: Warning: failed to reserve range 00010000-00110000
preloader: Warning: failed to reserve range 0000000000010000-0000000000110000
+ LAUNCHER_PID_HEX=00000178
+ LAUNCHER_PID=376
+ [[ ! -z '' ]]
+ wine start /exec /bin/runfromprocess-rs.exe 376 ZwiftApp.exe
preloader: Warning: failed to reserve range 00010000-00110000
019c:err:ole:CoGetContextToken apartment not initialised
preloader: Warning: failed to reserve range 00010000-00110000
preloader: Warning: failed to reserve range 0000000000010000-0000000000110000
preloader: Warning: failed to reserve range 0000000000010000-0000000000110000
+ sleep 3
017c:err:combase:RoGetActivationFactory Failed to find library for L"Windows.Foundation.Diagnostics.AsyncCausalityTracer"
preloader: Warning: failed to reserve range 0000000000010000-0000000000110000
+ pgrep -f ZwiftApp.exe
Killing uneccesary applications
+ echo 'Killing uneccesary applications'
+ pkill ZwiftLauncher
+ pkill ZwiftWindowsCra
+ pkill -f MicrosoftEdgeUpdate
+ wineserver -w
$ podman exec -it zwift-perrin4869 /bin/bash
root@04a527c4ddd3:/# ls -al /run/user/1000/pulse
total 8
drwx------ 2 user users   80 Apr 25 03:48 .
drwxr-xr-x 1 user users 4096 Apr 25 13:57 ..
srwxrwxrwx 1 user users    0 Apr 25 03:48 native
-rw-r--r-- 1 user users    5 Apr 25 03:48 pid
$ ls -lah /run/user/1000/pulse
total 4.0K
drwx------  2 perrin4869 users   80 Apr 25 12:48 .
drwx------ 17 perrin4869 users  500 Apr 25 23:00 ..
srwxrwxrwx  1     100999 100099   0 Apr 25 12:48 native
-rw-r--r--  1     100999 100099   5 Apr 25 12:48 pid
hobeone commented 7 months ago

I'm really not sure how /run/user/1000/pulse is being set to 100999:100099. Perhaps this is something that podman is doing when mapping the volumes.

in #98 the userns argument was dropped from the podman command line I wonder if some default is set for you that messing with this.

perrin4869 commented 7 months ago

for reference, I am running podman version 4.7.2 on slackware-current. I can try to look into it more carefully this weekend or sometime next week, in case no one else can reproduce this. Probably irrelevant, but I'm running pipewire-1.0.5

perrin4869 commented 7 months ago

ok, it is indeed caused by podman: https://stackoverflow.com/questions/70844126/how-to-mount-a-directory-such-that-it-has-same-uid-gid-in-host-as-well-as-contai I think that if we want to support both podman and docker, we need to use userns for podman, and the other method for docker, or just decide that we support only one of the container systems?

hobeone commented 7 months ago

I'll leave it up to @netbrain to talk about supporting both.

Supporting both will need to refactor the entrypoint & setup script to understand which container environment it's running in.

hobeone commented 7 months ago

Actually could you try adding --userns=nomap to the podman command line in zwift.sh? Reading the docs seems like that would make it operate like docker?

perrin4869 commented 7 months ago

just tried, it ended up with an error:

$ podman logs -f zwift-perrin4869
++ id -u user
+ USER_UID=1000
++ id -g user
+ USER_GID=1000
+ '[' -n 1000 ']'
+ '[' 1000 -eq 1000 ']'
+ USER_UID=1000
+ '[' -n 100 ']'
+ '[' 100 -eq 100 ']'
+ USER_GID=100
+ usermod -o -u 1000 user
usermod: no changes
+ groupmod -o -g 100 user
+ chown -R 1000:100 /home/user
+ mkdir -p /run/user/1000
+ chown -R user:user /run/user/1000
chown: cannot read directory '/run/user/1000/pulse': Permission denied
netbrain commented 7 months ago

@perrin4869 would you mind trying out the different options for this flag as shown in the documentation?

perrin4869 commented 7 months ago

of course I can keep trying, but I'm just curious, are you guys not able to reproduce this issue? Or just using docker?

netbrain commented 7 months ago

I would like to support both docker and podman. And even other container runtimes. However personally I'm using docker at the moment.

perrin4869 commented 7 months ago

Gotcha, I'll see when I can keep digging into this, but honestly I hope someone more well-versed in linux containers can jump in 😅

netbrain commented 7 months ago

If you get stuck then I'll try to see if I can't reproduce it. But I'm quite busy rn. Might have to wait a week or two. 🫣

hobeone commented 7 months ago

I'm just using docker as well and am away from a place I can test podman for a bit.

One last shot though, the docs say that an empty argument (e.g. --userns="") will map the default user to the root user in the container. Maybe that mode will work like Docker?

perrin4869 commented 7 months ago

I just tried --userns="", but I had the same issue, the permissions change to 100999. I have a few more clarifications to make. Using docker, I have never actually been able to get zwift to play audio, which is why I originally tried to run on podman, and was pleasantly surprised when it finally worked. Even with the recent changes to the entrypoint and to the zwift.sh script, running on docker will not play audio.

I did find that by running the container with the following options, podman compatibility is restored for me:

    $([ "$CONTAINER_TOOL" = "podman" ] && echo '--userns=keep-id') \
    $([ "$CONTAINER_TOOL" = "podman" ] && echo '--entrypoint /bin/setup_and_run_zwift') \

I could try to get investigate further the docker incompatibility in the future 😅