evdev: trust fds provided by a seat manager

These changes make libinput trust file descriptors provided by a seat manager
(e.g. seatd) even when the device nodes are not accessible on the filesystem.
This enables use cases where libinput consumers (e.g. wayland compositors) run
inside containers without devfs.

Closes: #1280

Signed-off-by: Quentin Thébault <quentin.thebault@defenso.fr>
Sponsored-by: Defenso
This commit is contained in:
Quentin Thébault 2026-04-21 15:08:45 +09:00
parent e53c2141b3
commit 0c1c566c3d
2 changed files with 21 additions and 11 deletions

View file

@ -2095,23 +2095,21 @@ static bool
evdev_device_have_same_syspath(struct udev_device *udev_device, int fd)
{
struct udev *udev = udev_device_get_udev(udev_device);
struct udev_device *udev_device_new = NULL;
_unref_(udev_device) *udev_device_new = NULL;
struct stat st;
bool rc = false;
if (fstat(fd, &st) < 0)
goto out;
return false;
udev_device_new = udev_device_new_from_devnum(udev, 'c', st.st_rdev);
/* In a jail/container where devfs doesn't expose the device, we
* cannot verify the syspath. Trust the fd provider (e.g. seatd).
*/
if (!udev_device_new)
goto out;
return true;
rc = streq(udev_device_get_syspath(udev_device_new),
udev_device_get_syspath(udev_device));
out:
if (udev_device_new)
udev_device_unref(udev_device_new);
return rc;
return streq(udev_device_get_syspath(udev_device_new),
udev_device_get_syspath(udev_device));
}
static bool

View file

@ -332,8 +332,20 @@ udev_device_from_devnode(struct libinput *libinput,
struct stat st;
size_t count = 0;
if (stat(devnode, &st) < 0)
if (stat(devnode, &st) < 0) {
#ifdef __FreeBSD__
/*
* If stat fails (e.g. device node not visible in a jail), fall
* back to creating a udev device directly from the devnode
* path. This works in FreeBSD because libudev-devd constructs
* devices using the information exposed by the kernel through
* the sysctl interface.
*/
return udev_device_new_from_syspath(udev, devnode);
#else
return NULL;
#endif
}
dev = udev_device_new_from_devnum(udev, 'c', st.st_rdev);