devd.conf

As I understand it devd.conf() can be configure to initiate an action when a particular device is present or becomes attached...

Is anyone aware of any examples showing how to execute a program when a USB device is inserted?

This is a section from devd.conf() which I may be able modify to do what I want:-

Code:
#
     # Match a USB device type
     #
     notify 0 {
         match "system"             "USB";
         match "subsystem"             "INTERFACE";
         match "type"             "ATTACH";
         match "intclass"             "0x0e";
         action "logger USB    video device attached";
     };
 
I'm not aware of any examples from mind but I am curious: what kind of action would you want to perform? Because if you're looking at basic actions such as setting up a specific permission then /etc/devfs.conf might be a better choice.
 
I'm not aware of any examples from mind but I am curious: what kind of action would you want to perform? Because if you're looking at basic actions such as setting up a specific permission then /etc/devfs.conf might be a better choice.

I want to run usb_modeswitch when a USB modem is inserted.
 
Do a "man devd.conf". Then look under "Sub-statements" at "action", which shows an example of running a script (in that case pccard_ether) when a device is detected. You should be able to put your usb_modeswitch command in there. In the man page is also a list of variables you can use in executing the command, you probably need at least $device-name.

The only thing that worries me a little bit: When you run usb_modeswitch, it will probably change the USB device ID of the device. Which means that now the kernel will recognize that the device that just appeared immediately vanishes, and a different one appears. Which in turn means that devd needs to run again, immediately. I hope it does that correctly. And if you are really evil (don't do that!), you could ping-pong there with another command and make devd run in an infinite loop.
 
After rummaging through the file system I came across .etc/devd/conf and wondered if it might be more appropriate to add something there... there are 2722 entries and all include vendor, product and action...
 
If you can find an entry there for your device, that would be the appropriate place to modify. And if there are other similar devices listed nearby, that would be a good place to add your device.

Only warning: those files may require special handling during an upgrade. What I do is: I mark all my changes in these files with a clear marker (like a comment "# RalphBSz 20180427 added support for purple elephant with USB connector on its tail"). Then after an upgrade, I can always look for my markers using grep (including in the backup = snapshot taken before the upgrade) and decide whether my changes need to be re-applied, modified, taken out, or whatever.
 
Back
Top