[systemd-devel] udev rules environment variable

Kay Sievers kay at vrfy.org
Tue Dec 17 10:59:47 PST 2013


On Tue, Dec 17, 2013 at 6:57 PM, Robert Milasan <rmilasan at suse.com> wrote:
> On Tue, 17 Dec 2013 17:36:21 +0100
> "Kay Sievers" <kay at vrfy.org> wrote:
>
>> On Tue, Dec 17, 2013 at 2:05 PM, Robert Milasan <rmilasan at suse.com>
>> wrote:
>> > On Tue, 17 Dec 2013 13:54:34 +0100
>> > "Martin Pitt" <martin.pitt at ubuntu.com> wrote:
>> >
>> >> Robert Milasan [2013-12-17 12:44 +0100]:
>> >> > I have this rule as a test, but doesn't do squat (meaning it
>> >> > doesnt work) :)
>> >> >
>> >> > ACTION=="add", SUBSYSTEM=="net", KERNEL=="?*",
>> >> > ENV{test_device}="1"
>> >> >
>> >> > ACTION=="remove", SUBSYSTEM=="net", KERNEL=="?*",
>> >> > ENV{test_device}=="1", RUN+="/bin/sh -c 'echo test_device
>> >> > > /tmp/test_device.log'"
>> >>
>> >> Drop the KERNEL== bits. Network devices don't have a /dev/...
>> >> device node in Linux, so KERNEL will never be set for those.
>>
>> KERNEL is the device name in /sys, without the leading path. It is in
>> almost all cases also the name in /dev, but there are some
>> differences. And right, it is always set, there is never a point to do
>> such a match.
>>
>> > Even without the KERNEL== doesn't seem to work:
>>
>> It's pointless to match that, so it should not make a difference.
>>
>> > I'm testing this by first removing the network device (ex. rmmod
>> > e1000), so I can have first an ADD event and then a REMOVE event, by
>> > removing again the module, so:
>> >
>> > rmmod e1000 (remove first)
>> > modprobe e1000 (ADD event, set the test_device var to 1)
>> > rmmod e1000 (REMOVE event, get the test_device value)
>> >
>> > This doesn't seem to work, or at least it looks like that.
>>
>> How old is your udev? You are not possibly talking about years old
>> versions, right?
>>
>> Kay
>>
>
> The tests are run using udev 208 (systemd 208).

Works just fine here as expected, it's probably something in your setup.

Kay

# head -2 /etc/udev/rules.d/10-local.rules
ACTION=="add", SUBSYSTEM=="net", ENV{test_device}="1"
ACTION=="remove", SUBSYSTEM=="net", ENV{test_device}=="1",
RUN+="/bin/logger $env{test_device}"

# udevadm monitor -p -u &

# modprobe dummy
UDEV  [58102.666415] add      /devices/virtual/net/dummy0 (net)
ACTION=add
DEVPATH=/devices/virtual/net/dummy0
IFINDEX=5
INTERFACE=dummy0
SEQNUM=2591
SUBSYSTEM=net
SYSTEMD_ALIAS=/sys/subsystem/net/devices/dummy0
TAGS=:systemd:
USEC_INITIALIZED=102664557
test_device=1

[root at lon systemd]# rmmod dummy
UDEV  [58110.298302] remove   /devices/virtual/net/dummy0 (net)
ACTION=remove
DEVPATH=/devices/virtual/net/dummy0
IFINDEX=5
INTERFACE=dummy0
SEQNUM=2596
SUBSYSTEM=net
SYSTEMD_ALIAS=/sys/subsystem/net/devices/dummy0
TAGS=:systemd:
USEC_INITIALIZED=102664557
test_device=1

# journalctl -n 2
-- Logs begin at Sat 2013-12-14 03:17:23 CET, end at Tue 2013-12-17
19:55:28 CET. --
Dec 17 19:55:28 lon gnome-session[442]: Gjs-Message: JS LOG: Removing
a network device that was not added
Dec 17 19:55:28 lon logger[20316]: 1


More information about the systemd-devel mailing list