Skip to content

Commit

Permalink
cmd/snap-device-helper: do not read sysfs directly
Browse files Browse the repository at this point in the history
udev does that for us and provides all the information we need even
for a delete event. So we can know if a device is a block without
guessing.
  • Loading branch information
valentindavid authored and Meulengracht committed Feb 12, 2024
1 parent f5f241c commit 904b283
Show file tree
Hide file tree
Showing 69 changed files with 215 additions and 321 deletions.
15 changes: 10 additions & 5 deletions cmd/snap-device-helper/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@
#include "snap-device-helper.h"

int main(int argc, char *argv[]) {
if (argc < 5) {
int old_invocation_detected = (argc >= 5);

if ((argc != 2) && !old_invocation_detected) {
die("incorrect number of arguments");
}

struct sdh_invocation inv = {
.action = argv[1],
.tagname = argv[2],
.devpath = argv[3],
.majmin = argv[4],
.action = getenv("ACTION"),
.tagname = old_invocation_detected?argv[2]:argv[1],
.major = getenv("MAJOR"),
.minor = getenv("MINOR"),
.subsystem = getenv("SUBSYSTEM"),
};

return snap_device_helper_run(&inv);
}
233 changes: 72 additions & 161 deletions cmd/snap-device-helper/snap-device-helper-test.c

Large diffs are not rendered by default.

79 changes: 28 additions & 51 deletions cmd/snap-device-helper/snap-device-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

#include "snap-device-helper.h"

static unsigned long must_strtoul(char *str) {
char *end = str;
static unsigned long must_strtoul(const char *str) {
char *end = NULL;
unsigned long val = strtoul(str, &end, 10);
if (*end != '\0') {
die("malformed number \"%s\"", str);
Expand Down Expand Up @@ -143,22 +143,37 @@ static char *udev_to_security_tag(const char *udev_tag) {
return tag;
}

/* sysroot can be mocked in tests */
static const char *sysroot = "/";

int snap_device_helper_run(const struct sdh_invocation *inv) {
const char *action = inv->action;
const char *udev_tagname = inv->tagname;
const char *devpath = inv->devpath;
const char *majmin = inv->majmin;
const char *major = inv->major;
const char *minor = inv->minor;
const char *subsystem = inv->subsystem;

bool allow = false;

if (strlen(majmin) < 3) {
die("no or malformed major/minor \"%s\"", majmin);
if ((major == NULL) && (minor == NULL)) {
/* no device node */
return 0;
}
if ((major == NULL) || (minor == NULL)) {
die("incomplete major/minor");
}
if (subsystem != NULL) {
/* ignore kobjects that are not devices */
if (strcmp(subsystem, "subsystem") == 0) {
return 0;
}
if (strcmp(subsystem, "module") == 0) {
return 0;
}
if (strcmp(subsystem, "drivers") == 0) {
return 0;
}
}
if (strlen(devpath) <= strlen("/devices/")) {
die("no or malformed devpath \"%s\"", devpath);

if (action == NULL) {
die("ERROR: no action given");
}
if (sc_streq(action, "bind") || sc_streq(action, "add") || sc_streq(action, "change")) {
allow = true;
Expand All @@ -177,33 +192,8 @@ int snap_device_helper_run(const struct sdh_invocation *inv) {

char *security_tag SC_CLEANUP(sc_cleanup_string) = udev_to_security_tag(udev_tagname);

int devtype = S_IFCHR;
/* find out the actual subsystem */
char sysdevsubsystem[PATH_MAX] = {0};
char fullsubsystem[PATH_MAX] = {0};
sc_must_snprintf(sysdevsubsystem, sizeof(sysdevsubsystem), "%s/sys/%s/subsystem", sysroot, devpath);
if (readlink(sysdevsubsystem, fullsubsystem, sizeof(fullsubsystem)) < 0) {
if (errno == ENOENT && sc_streq(action, "remove")) {
// on removal the devices are going away, so it is possible that the
// symlink is already gone, in which case try guessing the type like
// the old shell-based snap-device-helper did:
//
// > char devices are .../nvme/nvme* but block devices are
// > .../nvme/nvme*/nvme*n* and .../nvme/nvme*/nvme*n*p* so if have a
// > device that has nvme/nvme*/nvme*n* in it, treat it as a block
// > device
if ((fnmatch("*/block/*", devpath, 0) == 0) || (fnmatch("*/nvme/nvme*/nvme*n*", devpath, 0) == 0)) {
devtype = S_IFBLK;
}
} else {
die("cannot read symlink %s", sysdevsubsystem);
}
} else {
char *subsystem = basename(fullsubsystem);
if (sc_streq(subsystem, "block")) {
devtype = S_IFBLK;
}
}
int devtype = ((subsystem != NULL) && (strcmp(subsystem, "block") == 0))?S_IFBLK:S_IFCHR;

sc_device_cgroup *cgroup = sc_device_cgroup_new(security_tag, SC_DEVICE_CGROUP_FROM_EXISTING);
if (!cgroup) {
if (errno == ENOENT) {
Expand All @@ -213,19 +203,6 @@ int snap_device_helper_run(const struct sdh_invocation *inv) {
die("cannot create device cgroup wrapper");
}

/* the format is <major>:<minor> */
char *major SC_CLEANUP(sc_cleanup_string) = sc_strdup(majmin);
char *sep = strchr(major, ':');
// sep is always \0 terminated so this checks if the part after ":" is empty
if (sep == NULL || sep[1] == '\0') {
/* not found, or a last character */
die("malformed major:minor string: %s", major);
}
/* set an end for the major number string */
*sep = '\0';
sep++;
char *minor = sep;

int devmajor = must_strtoul(major);
int devminor = must_strtoul(minor);
debug("%s device type is %s, %d:%d", inv->action, (devtype == S_IFCHR) ? "char" : "block", devmajor, devminor);
Expand Down
5 changes: 3 additions & 2 deletions cmd/snap-device-helper/snap-device-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
struct sdh_invocation {
const char *action;
const char *tagname;
const char *devpath;
const char *majmin;
const char *major;
const char *minor;
const char *subsystem;
};

int snap_device_helper_run(const struct sdh_invocation *inv);
Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/acrn_support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (s *acrnSupportInterfaceSuite) TestUDevSpec(c *C) {
c.Assert(spec.Snippets(), HasLen, 2)
c.Assert(spec.Snippets()[0], Equals, `# acrn-support
KERNEL=="acrn_hsm", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%s/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir))
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%s/snap-device-helper snap_consumer_app"`, dirs.DistroLibExecDir))
}

func (s *acrnSupportInterfaceSuite) TestStaticInfo(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/allegro_vcu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ SUBSYSTEM=="allegro_encode_class", KERNEL=="allegroIP", TAG+="snap_consumer_app"
c.Assert(spec.Snippets(), testutil.Contains, `# allegro-vcu
SUBSYSTEM=="char", KERNEL=="dmaproxy", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(
`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir))
`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_consumer_app"`, dirs.DistroLibExecDir))
}

func (s *AllegroVcuInterfaceSuite) TestStaticInfo(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/alsa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *AlsaInterfaceSuite) TestUDevpec(c *C) {
c.Assert(spec.Snippets(), HasLen, 8)
c.Assert(spec.Snippets(), testutil.Contains, `# alsa
KERNEL=="pcmC[0-9]*D[0-9]*[cp]", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir))
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_consumer_app"`, dirs.DistroLibExecDir))
}

func (s *AlsaInterfaceSuite) TestStaticInfo(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/audio_playback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ KERNEL=="controlC[0-9]*", TAG+="snap_audio-playback_app1"`)
KERNEL=="pcmC[0-9]*D[0-9]*[cp]", TAG+="snap_audio-playback_app1"`)
c.Assert(spec.Snippets(), testutil.Contains, `# audio-playback
KERNEL=="timer", TAG+="snap_audio-playback_app1"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_audio-playback_app1", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_audio-playback_app1 $devpath $major:$minor"`, dirs.DistroLibExecDir))
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_audio-playback_app1", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_audio-playback_app1"`, dirs.DistroLibExecDir))
}

func (s *AudioPlaybackInterfaceSuite) TestInterfaces(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/block_devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (s *blockDevicesInterfaceSuite) TestUDevSpec(c *C) {
c.Assert(spec.Snippets(), HasLen, 5)
c.Assert(spec.Snippets()[0], Equals, `# block-devices
KERNEL=="megaraid_sas_ioctl_node", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir))
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_consumer_app"`, dirs.DistroLibExecDir))
}

func (s *blockDevicesInterfaceSuite) TestStaticInfo(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/bluetooth_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (s *BluetoothControlInterfaceSuite) TestUDevSpec(c *C) {
SUBSYSTEM=="bluetooth", TAG+="snap_other_app2"`)
c.Assert(spec.Snippets(), testutil.Contains, `# bluetooth-control
SUBSYSTEM=="BT_chrdev", TAG+="snap_other_app2"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_other_app2", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_other_app2 $devpath $major:$minor"`, dirs.DistroLibExecDir))
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_other_app2", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_other_app2"`, dirs.DistroLibExecDir))
}

func (s *BluetoothControlInterfaceSuite) TestInterfaces(c *C) {
Expand Down
4 changes: 2 additions & 2 deletions interfaces/builtin/bluez_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (s *BluezInterfaceSuite) TestUDevSpec(c *C) {
c.Assert(spec.Snippets(), HasLen, 2)
c.Assert(spec.Snippets(), testutil.Contains, `# bluez
KERNEL=="rfkill", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir))
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_consumer_app"`, dirs.DistroLibExecDir))

// on a classic system with bluez slot coming from the core snap.
restore = release.MockOnClassic(true)
Expand All @@ -257,7 +257,7 @@ KERNEL=="rfkill", TAG+="snap_consumer_app"`)
c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.coreSlot), IsNil)
c.Assert(spec.Snippets(), HasLen, 2)
c.Assert(spec.Snippets()[0], testutil.Contains, `KERNEL=="rfkill", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir))
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_consumer_app"`, dirs.DistroLibExecDir))

}

Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/broadcom_asic_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (s *BroadcomAsicControlSuite) TestUDevSpec(c *C) {
c.Assert(spec.Snippets(), HasLen, 3)
c.Assert(spec.Snippets(), testutil.Contains, `# broadcom-asic-control
SUBSYSTEM=="net", KERNEL=="bcm[0-9]*", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir))
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_consumer_app"`, dirs.DistroLibExecDir))
}

func (s *BroadcomAsicControlSuite) TestKModSpec(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/camera_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (s *CameraInterfaceSuite) TestUDevSpec(c *C) {
KERNEL=="video[0-9]*", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, `# camera
KERNEL=="vchiq", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir))
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_consumer_app"`, dirs.DistroLibExecDir))
}

func (s *CameraInterfaceSuite) TestStaticInfo(c *C) {
Expand Down
4 changes: 2 additions & 2 deletions interfaces/builtin/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ slots:
c.Assert(spec.Snippets(), DeepEquals, []string{
`# common
KERNEL=="foo", TAG+="snap_consumer_app-a"`,
fmt.Sprintf(`TAG=="snap_consumer_app-a", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app-a $devpath $major:$minor"`, dirs.DistroLibExecDir),
fmt.Sprintf(`TAG=="snap_consumer_app-a", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_consumer_app-a"`, dirs.DistroLibExecDir),
// NOTE: app-b is unaffected as it doesn't have a plug reference.
`# common
KERNEL=="foo", TAG+="snap_consumer_app-c"`,
fmt.Sprintf(`TAG=="snap_consumer_app-c", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app-c $devpath $major:$minor"`, dirs.DistroLibExecDir),
fmt.Sprintf(`TAG=="snap_consumer_app-c", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_consumer_app-c"`, dirs.DistroLibExecDir),
})

// connected plug udev rules are optional
Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/device_buttons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (s *DeviceButtonsInterfaceSuite) TestUDevSpec(c *C) {
KERNEL=="event[0-9]*", SUBSYSTEM=="input", ENV{ID_INPUT_KEY}=="1", ENV{ID_INPUT_KEYBOARD}!="1", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, `# device-buttons
KERNEL=="full", SUBSYSTEM=="mem", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir))
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_consumer_app"`, dirs.DistroLibExecDir))
c.Assert(spec.TriggeredSubsystems(), DeepEquals, []string{"input/key"})
}

Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/dm_crypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ KERNEL=="dm-[0-9]", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, `# dm-crypt
SUBSYSTEM=="block", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains,
fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir))
fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_consumer_app"`, dirs.DistroLibExecDir))
}

func (s *DmCryptInterfaceSuite) TestSeccompSpec(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/dsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (s *dspSuite) TestUDevConnectedPlugAmbarella(c *C) {
c.Assert(spec.Snippets(), HasLen, 6)
c.Assert(spec.Snippets(), testutil.Contains, `# dsp
KERNEL=="iav", TAG+="snap_my-device_svc"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_my-device_svc", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_my-device_svc $devpath $major:$minor"`, dirs.DistroLibExecDir))
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_my-device_svc", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_my-device_svc"`, dirs.DistroLibExecDir))
}

func (s *dspSuite) TestUDevConnectedPlugNoFlavor(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/dvb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (s *DvbInterfaceSuite) TestUDevSpec(c *C) {
c.Assert(spec.Snippets(), HasLen, 2)
c.Assert(spec.Snippets(), testutil.Contains, `# dvb
SUBSYSTEM=="dvb", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir))
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_consumer_app"`, dirs.DistroLibExecDir))
}

func (s *DvbInterfaceSuite) TestStaticInfo(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/fpga_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (s *FpgaInterfaceSuite) TestUDevSpec(c *C) {
c.Assert(spec.Snippets(), HasLen, 2)
c.Assert(spec.Snippets(), testutil.Contains, `# fpga
SUBSYSTEM=="misc", KERNEL=="fpga[0-9]*", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir))
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_consumer_app"`, dirs.DistroLibExecDir))
}

func (s *FpgaInterfaceSuite) TestStaticInfo(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/framebuffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (s *FramebufferInterfaceSuite) TestUDevSpec(c *C) {
c.Assert(spec.Snippets(), HasLen, 2)
c.Assert(spec.Snippets()[0], Equals, `# framebuffer
KERNEL=="fb[0-9]*", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir))
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_consumer_app"`, dirs.DistroLibExecDir))
}

func (s *FramebufferInterfaceSuite) TestStaticInfo(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/fuse_support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (s *FuseSupportInterfaceSuite) TestUDevSpec(c *C) {
c.Assert(spec.Snippets(), HasLen, 2)
c.Assert(spec.Snippets(), testutil.Contains, `# fuse-support
KERNEL=="fuse", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir))
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_consumer_app"`, dirs.DistroLibExecDir))
}

func (s *FuseSupportInterfaceSuite) TestStaticInfo(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/fwupd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ KERNEL=="wmi/dell-smbios", TAG+="snap_uefi-fw-tools_app2"`)
c.Assert(snippets[11], Equals, `# fwupd
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", TAG+="snap_uefi-fw-tools_app2"`)

expected := fmt.Sprintf(`TAG=="snap_uefi-fw-tools_app2", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_uefi-fw-tools_app2 $devpath $major:$minor"`, dirs.DistroLibExecDir)
expected := fmt.Sprintf(`TAG=="snap_uefi-fw-tools_app2", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_uefi-fw-tools_app2"`, dirs.DistroLibExecDir)
c.Assert(snippets[12], Equals, expected)

// The implicit slot found on classic systems does not generate any rules
Expand Down
2 changes: 1 addition & 1 deletion interfaces/builtin/hardware_random_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *HardwareRandomControlInterfaceSuite) TestUDevSpec(c *C) {
c.Assert(spec.Snippets(), HasLen, 2)
c.Assert(spec.Snippets(), testutil.Contains, `# hardware-random-control
KERNEL=="hwrng", TAG+="snap_consumer_app"`)
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir))
c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", SUBSYSTEM!="module", SUBSYSTEM!="subsystem", RUN+="%v/snap-device-helper snap_consumer_app"`, dirs.DistroLibExecDir))
}

func (s *HardwareRandomControlInterfaceSuite) TestStaticInfo(c *C) {
Expand Down
Loading

0 comments on commit 904b283

Please sign in to comment.