@zyga, recently I was playing with udevadm and our cgroups handling and thought I found bugs in our cgroups handling. On reboot I found everything was working fine, so I thought of this thread. I then thought I remembered something about what is safe and not safe and remembered this thread:
https://lists.ubuntu.com/archives/ubuntu-devel/2009-January/027260.html
This is of course an ancient thread, but this struck me:
"Here’s a quick guide to what is safe to call:
…
I’ve installed udev rules and want udev to do something about it.
udevadm trigger --action=change
...
The action argument is of utmost importance. Without it, the
kernel will tell udev to treat all devices as *NEW*. This will
have lots of side-effects you are probably not expecting.
"change" is completely safe. It tells udev just to refresh
devices, and make sure everything's as it should be.
...
"
I then recalled that udev automatically detects changes to udev rules.
It seems all we need to do is udevadm trigger --action=change and skip everything else. Indeed, looking in /var/lib/dpkg/info/* I see most postinst scripts doing this (some include --subsystem, but thinking that isn’t strictly required).
I then checked this manually and by doing:
$ udevadm info /sys/devices/virtual/mem/kmsg
P: /devices/virtual/mem/kmsg
N: kmsg
E: DEVMODE=0644
E: DEVNAME=/dev/kmsg
E: DEVPATH=/devices/virtual/mem/kmsg
E: MAJOR=1
E: MINOR=11
E: SUBSYSTEM=mem
$ sudo sh -c 'echo "KERNEL==\"kmsg\", TAG+=\"snap_hello-world_sh\"" > /etc/udev/rules.d/snap.hello-world.rules'
$ cat /etc/udev/rules.d/snap.hello-world.rules
KERNEL=="kmsg", TAG+="snap_hello-world_sh"
# before udevadm trigger --action=change
$ udevadm info /sys/devices/virtual/mem/kmsgP: /devices/virtual/mem/kmsg
N: kmsg
E: DEVMODE=0644
E: DEVNAME=/dev/kmsg
E: DEVPATH=/devices/virtual/mem/kmsg
E: MAJOR=1
E: MINOR=11
E: SUBSYSTEM=mem
$ sudo udevadm trigger --action=change
# after udevadm trigger --action=change
$ udevadm info /sys/devices/virtual/mem/kmsg
P: /devices/virtual/mem/kmsg
N: kmsg
E: DEVMODE=0644
E: DEVNAME=/dev/kmsg
E: DEVPATH=/devices/virtual/mem/kmsg
E: MAJOR=1
E: MINOR=11
E: SUBSYSTEM=mem
E: TAGS=:snap_hello-world_sh:
E: USEC_INITIALIZED=8295994829
# remove the file and then run udevadm trigger --action=change
$ sudo rm -f /etc/udev/rules.d/snap.hello-world.rules
$ sudo udevadm trigger --action=change
$ udevadm info /sys/devices/virtual/mem/kmsg
P: /devices/virtual/mem/kmsg
N: kmsg
E: DEVMODE=0644
E: DEVNAME=/dev/kmsg
E: DEVPATH=/devices/virtual/mem/kmsg
E: MAJOR=1
E: MINOR=11
E: SUBSYSTEM=mem