4

Is it possible (and if so how) to tell udev to stop executing further rules for a certain device?

I know that there is an order/sequence of rules by the alphabetical naming of the udev files. Therefore it seems logical that earlier *.rules might want to prevent further (that is in the order later occuring rules) to be executed.

Let us assume I have a usb-memory-media which is via udev and its RUN+ script already mounted, I would dislike now that any other rule in the system tries (and probably fails) to yet again mount the device!

To facilitate responding I would like to also include an example: Let the rule be like this:

# in file 30.myusb.rules
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="1f75", ATTRS{idProduct}=="0902", RUN+="/bin/mount.30.1f75.0902.sh"

now I want this further (because of 31 > 30) rule not to happen

# in file 31.myusb.rules
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="1f75", ATTRS{idProduct}=="0902", RUN+="/bin/mount.31.1f75.0902.sh"

the "filter" used to make udev able to tell if the rule applies is the same for both rules, yet I wished the 31.myusb.rules rule not ever to happen.

I am looking hence for a way to tweek 30.myusb.rules in such a pseudo-code suggested way

# in file 30.myusb.rules
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="1f75", ATTRS{idProduct}=="0902", RUN+="/bin/mount.30.1f75.0902.sh"
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="1f75", ATTRS{idProduct}=="0902", STOP_FURTHER_RULES_WITH_THIS_FILTER

2 Answers 2

5

You can use GOTO in a rule to skip to a label as soon as the rule has been applied. If the label is at the very end of the rules, then all subsequent rules are skipped.

So in 30.myusb.rules:

ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="1f75", ATTRS{idProduct}=="0902", RUN+="/bin/mount.30.1f75.0902.sh", GOTO="myusb_end"

And at the end of 31.myusb.rules:

LABEL="myusb_end"

Or use GOTO="very_end", and put LABEL="very_end" in a file that is loaded last (/etc/udev/rules.d/zzzzzzzz.rules).

4

You must use := instead of +=.

# in file 30.myusb.rules
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="1f75", ATTRS{idProduct}=="0902", RUN:="/bin/mount.30.1f75.0902.sh"

From the man page,

   "="
       Assign a value to a key. Keys that represent a list are reset and
       only this single value is assigned.

   "+="
       Add the value to a key that holds a list of entries.

   ":="
       Assign a value to a key finally; disallow any later changes.

You must log in to answer this question.

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