From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aras Vaichas Date: Thu, 21 Aug 2008 07:17:20 +0000 Subject: Re: ENV variable scope question Message-Id: <48AD1680.8010705@magtech.com.au> List-Id: References: <48ACC6DD.4070705@magtech.com.au> In-Reply-To: <48ACC6DD.4070705@magtech.com.au> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-hotplug@vger.kernel.org Kay Sievers wrote: > On Thu, Aug 21, 2008 at 03:37, Aras Vaichas wrote: > >> Hi, I'm looking to unload a userspace driver when a particular device is >> removed. >> >> My load rule is this: >> >> ACTION="add",SUBSYSTEM="usb_endpoint",ATTR{device/manufacturer}="Crystalfontz", >> RUN+="/usr/bin/sv up lcdd" >> >> Now the problem was that when I disconnect the device there is no longer >> a "device/manufacturer" file, so I added an environment variable >> LCDD_DEVICE to the rule: >> >> ACTION="add",SUBSYSTEM="usb_endpoint",ATTR{device/manufacturer}="Crystalfontz", >> ENV{LCDD_DEVICE}="%k", RUN+="/usr/bin/sv up lcdd" >> > > Why do you match against the endpoint? These devices do not do anything. > > You should also never use the "device" link, it's deprecated and udev > should print a warning to the logs. > Well the problem was that the device uses a common USB-to-serial chip (FTDI) and they didn't change the VID/PID numbers for their product. This means that I could plug in a USB-to-serial cable which uses the same chip and I wouldn't know the difference if I just looked at the VID/PID numbers. So to avoid any ambiguity I wanted to load the application only when the exact device was plugged in. The manufacturer field seemed to be the best discriminator. Is there a better way to distinguish between the same USB-serial chip that is used in different devices? For example, I want to add a symlink for ttyUSB[0-9] only when the Manufucturer is Crystalfontz, so I do: ACTION="add", KERNEL="ttyUSB[0-9]", ATTR{../../../../manufacturer}="Crystalfontz", SYMLINK+="lcd" Is this safer? Should I use this same method for loading the driver? >> ACTION="remove", ENV{LCDD_DEVICE}!="", RUN+="... remove the driver ..." >> > By matching on the endpoint, you get several events which will all > trigger your script. Try using the USB-device only, by adding: > ENV{DEVTYPE}="usb_device" > Ok. > Try setting: > ENV{REMOVE_CMD}="/bin/something" > with the "add" rule, it should be called by udev itself on "remove". > Good idea, use a standard naming scheme. So, does udev maintain a separate environment space for each /dev point that it processes? Aras ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________