2

How does the link_priority option in udev rules relate to the orders in which rules are processed? For example, take this snippet from the default udev rules:

50-udev-default.rules:

# select "system RTC" or just use the first one
SUBSYSTEM=="rtc", ATTR{hctosys}=="1", SYMLINK+="rtc"
SUBSYSTEM=="rtc", KERNEL=="rtc0", SYMLINK+="rtc", OPTIONS+="link_priority=-100"

This will create a /dev/rtc symlink to the RTC device which has the hctosys attribute set, i.e. the one that provided the system time. Or, if no RTC device provided the system time, this will just pick the /dev/rtc0.

Now let's assume we reverse the order. We could even split them in separate files:

10-custom.rules:
SUBSYSTEM=="rtc", KERNEL=="rtc0", SYMLINK+="rtc", OPTIONS+="link_priority=-100"

[...]

50-udev-default.rules:
SUBSYSTEM=="rtc", ATTR{hctosys}=="1", SYMLINK+="rtc"

Would this be equivalent to the first version? Or will this result in a first symlink being created to /dev/rtc0, which would then be overwritten with a second symlink to whatever RTC device provided the system time (assuming it was a different one than rtc0, that is) ?

1 Answer 1

0

Yes, reversing the order will be equivalent, independent whether reversed in the original /lib/udev/rules.d/50-udev-default.rules or in a separate /etc/udev/rules.d/10-custom.rules file.

What defines the symlink in this case is the link_priority value. The default link_priority is 0, so as long there is an rtc providing hctosys it will always be higher than the rtc0's link_priority=-100.

Note that changing the rule to a higher link_priority in a custom 10-custom.rules file won't work as it will be overridden by the original 50-udev-default.rules file as it has a higher file number. So use a number > 50 in your custom rule filename.

2
  • What do you mean with overriden? Won't both rules be processed regardless of whether they are in the same file or in separate files?
    – Grodriguez
    Dec 19, 2023 at 11:55
  • If in the file 10-custom-rules you set a link-priority of 100 and it is defined at -100 in 50-udev-default.rules, the -100 will be the final value as for equal rules the higher file name will be the one that sets the value.
    – Martin
    Dec 19, 2023 at 12:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .