0

I have multiple udev rules that check if ATTRS{name}=="abc123" and invokes various functions if that device is present. These udev rules are located within multiple locations as this is being created within bitbake for a custom embedded OS. Now, if I want to change this device to test different hardware, this is too time consuming to change every ATTR{name} call every time.

My solution would be to define a var, e.g. $UDEVVAR="[device_name]" in some conf file (to be determined), and then change each ATTR{name} call to something like ATTR{name}=="${UDEVVAR}".

I've tested this approach in a local rule written for proof of concept, although the rule didn't invoke. This local rule was a bit different, though followed the same concept. Whatever flash drive I had lying around didn't have an ATTR{name} defined, so I used a usb mouse and that flash drive. This udev rule is:

SUBSYSTEM=="${UDEVVAR}", ACTION=="add", RUN+="/usr/local/bin/trigger.sh"

trigger.sh simply writes the date-time stamp to a log file. When hard coding SUBSYSTEM as =="block", the rule invokes successfully, although when defining UDEVVAR="block", the rule does not get invoked. The idea was, if that worked, then I would define UDEVVAR="hidraw" to test the mouse.

I can't seem to find much documentation on anyone trying to do something like this. I figure I'm making some sort of syntactical mistake, or maybe udev rules don't allow for something like this.

I appreciate any help!

1 Answer 1

0

One way to solve your problem is to generate your files from templates.

In a separate directory tree from your development environment, create copies of your files, but with the values you want to change replaced with, e.g.

ATTRS{name}="%%NAME%%"

Then, when you want "def456" , run the file through

sed -e 's/%%NAME%%/def456/' 

The m4 macro preprocessor (man m4;info m4) is handy for this.

Also see man -k template.

1
  • This would require that I know the other ATTRS{name}, right?
    – etfreima
    Apr 5, 2021 at 17:48

You must log in to answer this question.

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