Files
Oliver Calder 1848b1aedb interfaces/builtin: fix custom-device default udev kernel rules (#12833)
* interfaces/builtin: fix custom-device default udev kernel rules

The KERNEL value in udev rules must be the basename of the device path.
For devices for which there is not a matching kernel value specified in
the custom-device `udev-tagging` section, a default udev kernel rule is
generated.  Previously, https://github.com/snapcore/snapd/pull/12734
(and prior) generated these default rules by using the complete device
path relative to `/dev/`.  However, for device paths which are in
subdirectories of `/dev/`, this means that the kernel values were not
basenames, which violates the udev spec.

This commit changes this behavior to instead generate udev kernel rules
using the basename of each specified device.

Since ambiguity would arise if multiple devices had the same basename,
this change introduces a check to ensure that all the specified devices
have unique basenames.

Additionally, this commit introduces a check to ensure that all
specified kernel values in the `udev-tagging` section are basenames.

It is still the case that each specified kernel value must match one of
the specified devices.

There are currently problems with `vet` where it is claimed that several
of the `[]string` variables in `validateUDevDevicesUniqueBasenames()`
are unused.  These variables are used in a several ways, so further
investigation is required as to why this is the case.

Signed-off-by: Oliver Calder <oliver.calder@canonical.com>

* prompting/storage: fixed missing variable assignment from append()

Signed-off-by: Oliver Calder <oliver.calder@canonical.com>

* prompting/storage: fixed custom device duplicate basename error message

Signed-off-by: Oliver Calder <oliver.calder@canonical.com>

* interfaces/builtin: fixed custom-device unit tests introduced by commas in filepaths PR

Signed-off-by: Oliver Calder <oliver.calder@canonical.com>

* interfaces/builtin: adjusted custom-device comment for kernel not matching any devices

Signed-off-by: Oliver Calder <oliver.calder@canonical.com>

* interfaces/builtin: fixed unit test for when custom-device kernel does not match any device

Signed-off-by: Oliver Calder <oliver.calder@canonical.com>

* interfaces/builtin: moved custom-device unique basename check

This change moves the check for whether all specified devices have
unique basenames out of `validateUDevTaggingRule()` (which is called
once for each udev rule) into `BeforePrepareSlot()`, immediately after
the list of device paths is assembled and each path validated.  Thus, it
is only called once, before any rule validation begins.

Signed-off-by: Oliver Calder <oliver.calder@canonical.com>

---------

Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
2023-05-27 10:47:31 +02:00
..
2023-01-16 14:23:11 +01:00
2023-01-16 14:23:11 +01:00