hw-assign overwrites existing udev rules
| Affects | Status | Importance | Assigned to | Milestone | |
|---|---|---|---|---|---|
| | Snappy |
Critical
|
Unassigned | ||
Bug Description
Each call to hw-assign for a given snap overwrites the (possibly) existing udev rule in 70-snappy_
The list "write_path" in <snapname>
Expected behavior:
The udev rule "70-snappy_
Following a copy of the content of both files after a sequence of calls to hw-assign:
(amd64)
{
"write_path": [
"/dev/ttyUSB*",
"/dev/simlink",
"/dev/
"/dev/simlink3"
],
"read_path": [
"/run/
]
}
(amd64)
KERNEL=
(amd64)
Related branches
- John Lenton: Approve on 2015-09-25
-
Diff: 159 lines (+87/-9)3 files modified.bzrignore (+3/-0)
snappy/hwaccess.go (+71/-9)
snappy/hwaccess_test.go (+13/-0)
| description: | updated |
| Carlo Lobrano (c-lobrano) wrote : | #1 |
| Jamie Strandboge (jdstrand) wrote : | #2 |
I can confirm this.
| Changed in snappy: | |
| importance: | Undecided → Critical |
| status: | New → Triaged |
| Jamie Strandboge (jdstrand) wrote : | #3 |
Marking critical because hw-assign only works for single devices right now, which is not how it is supposed to work.
Test case:
$ ls /etc/udev/rules.d
$
$ sudo snappy hw-assign hello-world.
$ ls /etc/udev/rules.d
70-snappy_
$ cat /etc/udev/
KERNEL=="foo", TAG:="snappy-
$ sudo snappy hw-assign hello-world.
$ cat /etc/udev/
KERNEL=="bar", TAG:="snappy-
Now, unassign /dev/bar:
$ sudo snappy hw-unassign hello-world.
$ cat /etc/udev/
cat: /etc/udev/
(foo should still be there).
| Jamie Strandboge (jdstrand) wrote : | #4 |
Whoops, meant to show this too where /dev/foo was added first, then /dev/bar, then /dev/bar removed:
$ sudo snappy hw-assign hello-world.
'hello-
$ cat /etc/udev/
cat: /etc/udev/
| Jamie Strandboge (jdstrand) wrote : | #5 |
Furthermore, adding access to a snap and also a service/binary in the snap doesn't work right:
$ sudo snappy hw-assign hello-world.
'hello-
$ sudo snappy hw-assign hello-world.
'hello-
$ cat /etc/udev/
KERNEL=="bar", TAG:="snappy-
Adding access to multiple snaps doesn't work right either:
$ sudo snappy hw-assign hello-world.
'hello-
$ sudo snappy hw-assign ufw.sideload /dev/baz
'ufw.sideload' is now allowed to access '/dev/baz'
$ cat /etc/udev/
KERNEL=="foo", TAG:="snappy-
In this case the second command did not take at all.
| Carlo Lobrano (c-lobrano) wrote : | #6 |
Hello Jamie,
the second behavior you noticed (the missing of the udev rule file after unassignment of only 1 of the devices) is due to the fact that RemoveHWAssign method just removes the file, without looking at its content. In the branch where I propose the fix for this bug, I also fixed this particular effect.
My understanding was that only snaps can have devices assigned, this could be the explaination of the errors assigning devices to services/binaries in the snap
| Carlo Lobrano (c-lobrano) wrote : | #7 |
I double checked the case of assignment to multiple snaps, currently each snaps has its own udev rule file
$ sudo snappy hw-assign minicom.saviq /dev/test1
'minicom.saviq' is now allowed to access '/dev/test1'
$ sudo snappy hw-assign hello-world.
'hello-
$ ll /etc/udev/rules.d/
total 16
drwxr-xr-x 2 root root 4096 Sep 23 06:13 ./
drwxr-xr-x 4 root root 4096 Sep 18 13:31 ../
-rw-r--r-- 1 root root 81 Sep 23 06:13 70-snappy_
-rw-r--r-- 1 root root 73 Sep 23 06:13 70-snappy_
if this is the expected behavior, it should be ok
| Jamie Strandboge (jdstrand) wrote : | #8 |
Yeah, I just rechecked that-- I was wrong on that point. It is expected behavior, thanks for checking.
| Changed in snappy: | |
| status: | Triaged → Fix Committed |
| Changed in snappy: | |
| status: | Fix Committed → Fix Released |


This bug also affect the part of the code I am changing to fix Bug #1496319.
Since the fix for this bug should be simple (open the file in append mode, instead of writing a new file each time), I will propose a fix for this, before continuing with the fix for #1496319.