Best way to access /dev/uinput?

This should be enough, yes. You can test this by installing your snap and connect any existing interfaces you have, then modify /var/lib/snapd/apparmor/profiles/snap.yoursnap.cmd to have:

/dev/uinput rw,

then load the updated apparmor rules into the kernel:

$ sudo apparmor_parser -r /var/lib/snapd/apparmor/profiles/snap.yoursnap.cmd

If you don’t have /etc/udev.d/rules.d/70-snap.yoursnap.rules on your system, you can test your snap now. If you do, add to it:

# test
KERNEL=="uinput", TAG+="snap_yoursnap_cmd"

then run:

$ sudo udevadm trigger --subsystem-match=misc # make the rules apply
$ snap run --shell yoursnap.cmd  # launch a shell under yoursnap.cmd

then in another terminal run udevadm and check TAGS:

$ udevadm info /dev/uinput
...
E: TAGS=:uaccess:snap_yoursnap_cmd:seat:

if yoursnap_cmd is listed under TAGS, then things are working properly. You can exit the snap run --shell command and test your snap. Please note, that snapd will undo these from time to time so you might have to reapply the changes when testing.

I’ve added a TODO to add this interface in the next batch of updates.

1 Like