spa: v4l2: Use systemd-logind to listen for access changes

There is a race between logind applying ACLs to allow the active session
of a locally present user access to devices with a udev uaccess tag
(like /dev/video# nodes) getting applied vs wireplumber/pipewire starting.

Wireplumber/pipewire are part of the (user) default.target, which gets
started as soon as a user logs in and systemd --user is started for that
user, where as logind only starts applying the ACLs after the gnome-shell
associated logind session has been created.

This race may cause pipewire to not see v4l2 video sources at login,
this can be reproduced with these steps:

1. sudo setfacl --remove-all /dev/video*
2. systemctl --user restart pipewire
3. Now wp-ctl status will not show any video devices
   (like if pipewire was started before the udev uaccess ACLs got applied)
4. Do a switch to another (test) user without logging out, e.g. in GNOME
   go to the top right system menu press the power on/off icon and select
   "Switch User..."
5. Switch back to your normal user. Run getfacl /dev/video0 this will show
   your user has access now.
6. wp-ctl status should show the camera now, but it does not.

Fix pipewire not seeing v4l2 sources in this case by making v4l2-udev
monitor systemd-logind session changes and redoing the access() checks
on /dev/video# nodes when the session changes.

Closes: #3539
Closes: #3960
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
(cherry picked from commit 2a6ba61264)
This commit is contained in:
Hans de Goede 2024-09-10 11:14:35 +02:00 committed by Robert Mader
parent 0b54e568fa
commit 2cbbc4e7ac
2 changed files with 86 additions and 2 deletions

View file

@ -4,8 +4,11 @@ v4l2_sources = ['v4l2.c',
v4l2_dependencies = [ spa_dep, libinotify_dep ]
if libudev_dep.found()
v4l2_sources += [ 'v4l2-udev.c' ]
v4l2_dependencies += [ libudev_dep ]
v4l2_sources += [ 'v4l2-udev.c' ]
v4l2_dependencies += [ libudev_dep ]
if systemd_dep.found()
v4l2_dependencies += [ systemd_dep ]
endif
endif
v4l2lib = shared_library('spa-v4l2',