LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 11-30-2008, 08:09 AM   #1
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mandriva, Mandriva, Mandriva. (Three different releases depending on the computer)
Posts: 710

Rep: Reputation: 35
Cannot get even the simplest of (self made) udev rules to work


I am trying to put some udev rules in when I plug in a Hauppaugge box. The result of

udevinfo -a -p /sys/class/pvrusb2/sn-8563645/

is:

Code:
Udevinfo starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/class/pvrusb2/sn-8563645':
    KERNEL=="sn-8563645"
    SUBSYSTEM=="pvrusb2"
    DRIVER==""
    ATTR{v4l_minor_number}=="0"
    ATTR{v4l_radio_minor_number}=="64"
    ATTR{unit_number}=="0"
    ATTR{bus_info_str}=="usb 2-4 address 2"

  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb2/2-4':
    KERNELS=="2-4"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{dev}=="189:129"
    ATTRS{configuration}==""
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bmAttributes}=="c0"
    ATTRS{bMaxPower}=="  0mA"
    ATTRS{urbnum}=="1643"
    ATTRS{idVendor}=="2040"
    ATTRS{idProduct}=="2400"
    ATTRS{bcdDevice}=="0800"
    ATTRS{bDeviceClass}=="00"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{speed}=="480"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="2"
    ATTRS{version}==" 2.00"
    ATTRS{maxchild}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{authorized}=="1"
    ATTRS{manufacturer}=="Hauppauge"
    ATTRS{product}=="WinTV"
    ATTRS{serial}=="2401-00-0082ABBD"

  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb2':
    KERNELS=="usb2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{dev}=="189:128"
    ATTRS{configuration}==""
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bMaxPower}=="  0mA"
    ATTRS{urbnum}=="38"
    ATTRS{idVendor}=="0000"
    ATTRS{idProduct}=="0000"
    ATTRS{bcdDevice}=="0206"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{speed}=="480"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="1"
    ATTRS{version}==" 2.00"
    ATTRS{maxchild}=="6"
    ATTRS{quirks}=="0x0"
    ATTRS{authorized}=="1"
    ATTRS{manufacturer}=="Linux 2.6.24.7-server-2mnb ehci_hcd"
    ATTRS{product}=="EHCI Host Controller"
    ATTRS{serial}=="0000:00:1d.7"
    ATTRS{authorized_default}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:1d.7':
    KERNELS=="0000:00:1d.7"
    SUBSYSTEMS=="pci"
    DRIVERS=="ehci_hcd"
    ATTRS{vendor}=="0x8086"
    ATTRS{device}=="0x2836"
    ATTRS{subsystem_vendor}=="0x1170"
    ATTRS{subsystem_device}=="0x0040"
    ATTRS{class}=="0x0c0320"
    ATTRS{irq}=="20"
    ATTRS{local_cpus}=="ffffffff"
    ATTRS{modalias}=="pci:v00008086d00002836sv00001170sd00000040bc0Csc03i20"
    ATTRS{broken_parity_status}=="0"
    ATTRS{msi_bus}==""

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""
I have put the following in /etc/udev/rules.d as 10-hauppaugge_boxes.rules:

Code:
KERNEL=="sn-8563645", SUBSYSTEM=="pvrusb2", RUN="/home/myhomedir/myscript"
myscript is a very simple script that, just to show it's getting invoked runs kwrite.

myscript runs just fine if I invoke it manually, so I know that's right. I have been over and over various tutorials and it looks to me like what I am trying to do is correct. I have tried rebooting just in case start_udev is no good for restarting udev, but it simply refuses to work when I plug in my hauppaugge box. (The /sys/class/pvrusb2/8563645/ directory is filled once the box is plugged in, so it must be something to do with how I'm trying to use the udev rule.)

Can anyone see what I am doing wrong? Many thanks!
 
Old 11-30-2008, 09:27 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
If all the test script does is run kwrite, that might be the problem. A gui program needs to be either run as the user owning the x-session or be configured to connect to it. I'm not sure what user udev scripts run as, but I'm pretty sure it's not your main session user, so chances are the script is just not able to launch the program.

A better way to test a script like this is to have it log information to a text file.
 
Old 11-30-2008, 09:31 AM   #3
tredegar
Guru
 
Registered: May 2003
Location: London, UK
Distribution: Ubuntu 10.04, mostly
Posts: 6,007

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
If it helps, I run a script when my broadband mobile USB dongle is plugged in.
It works fine.
My rule is called 99-Huawei-e169.rules
Its permissions are:
Code:
-rw-r--r-- 1 root root  97 2008-07-05 15:24 99-sc-huawei-e169g.rules
It is just one line:
Code:
SUBSYSTEM=="usb" SYSFS{idProduct}=="1001", SYSFS{idVendor}=="12d1", RUN+="/usr/sbin/e169g-switch"
Note that my rule has a + sign in it. I forget now what this does, but it works.
So perhaps you could make a rule like this, looking for your product's SYSFS{idProduct} and SYSFS{idVendor} which I cave copied from your post.
Code:
SUBSYSTEM=="usb" SYSFS{idProduct}=="2400", SYSFS{idVendor}=="2040", RUN+="/home/myhomedir/myscript"
 
Old 11-30-2008, 09:34 AM   #4
tredegar
Guru
 
Registered: May 2003
Location: London, UK
Distribution: Ubuntu 10.04, mostly
Posts: 6,007

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
Good point David the H.
udev rules are run as root, and root will not be able to connect to DiBosco's desktop.
 
Old 11-30-2008, 10:17 AM   #5
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mandriva, Mandriva, Mandriva. (Three different releases depending on the computer)
Posts: 710

Original Poster
Rep: Reputation: 35
Chaps,

Many thanks for the suggestions. I have tried a few things following that.

I have now tried the following two rules file:

Code:
SUBSYSTEM=="usb" SYSFS{idProduct}=="2400", SYSFS{idVendor}=="2040", RUN+="/usr/sbin/myscript"
Code:
KERNEL=="sn-8563645", SUBSYSTEM=="pvrusb2", RUN+="/usr/sbin/myscript"
myscript simply contains this:

Code:
#!/bin/sh
echo "Hello" > log.txt
If I invoke the script as root, sure enough, the little log.txt containing Hello is there. However, no joy at all with udev invoking it.

Am I right in thinking start_udev is enough to run once a rules file is changed?

Last edited by DiBosco; 11-30-2008 at 10:18 AM.
 
Old 11-30-2008, 10:57 AM   #6
tredegar
Guru
 
Registered: May 2003
Location: London, UK
Distribution: Ubuntu 10.04, mostly
Posts: 6,007

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
Quote:
Am I right in thinking start_udev is enough to run once a rules file is changed?
I don't think so.
It's such a long time since I wrote my rule, I have forgotten (and, stupidly, did not make notes at the time).
From http://www.reactivated.net/writing_u...ml#terminology
Quote:
Assuming you are on a recent kernel with inotify support, udev will automatically monitor your rules directory and automatically pick up any modifications you make to the rule files.

Despite this, udev will not automatically reprocess all devices and attempt to apply the new rule(s). For example, if you write a rule to add an extra symbolic link for your camera while your camera is plugged in, you cannot expect the extra symbolic link to show up right away.

To make the symbolic link show up, you can either disconnect and reconnect your camera, or alternatively in the case of non-removable devices, you can run udevtrigger.

If your kernel does not have inotify support, new rules will not be detected automatically. In this situation, you must run udevcontrol reload_rules after making any rule file modifications for those modifications to take effect.
Or maybe (as root) you could try /etc/init.d/udev restart
 
Old 11-30-2008, 11:00 AM   #7
tredegar
Guru
 
Registered: May 2003
Location: London, UK
Distribution: Ubuntu 10.04, mostly
Posts: 6,007

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
Oh. I did make notes at the time:
After a rulechange I restarted udev with /etc/init.d/udev restart
 
Old 11-30-2008, 11:06 AM   #8
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mandriva, Mandriva, Mandriva. (Three different releases depending on the computer)
Posts: 710

Original Poster
Rep: Reputation: 35
Made a little progress with this rule:

Code:
KERNEL=="video[0-9]*", RUN+="/bin/sh -c '/etc/dynamic/scripts/myscript &'"
I copied the syntax from one of the other rules. I just searched for video as the box becomes /dev/video0 and Ekiga starts automatically when I plug the box in (always wondered how stuff like this worked!).

If I add anything like:

SUBSYSTEM=="pvrusb2"

Then it stops working. I could write a little script to look at what was in the subdirectories and act accordingly, but I get the feeling it should be easier than that.

Seems like once you change a rule the udev system just picks it up. I guess it parses the whole directory every time something's plugged in.

Many thanks for all the help, Tredegar.
 
Old 11-30-2008, 11:11 AM   #9
tredegar
Guru
 
Registered: May 2003
Location: London, UK
Distribution: Ubuntu 10.04, mostly
Posts: 6,007

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
I think you need to re-read http://www.reactivated.net/writing_udev_rules.html especially the bit about
Quote:
You may have noted the use of colour in the above examples. This is to demonstrate that while it is legal to combine the attributes from the device in question and a single parent device, you cannot mix-and-match attributes from multiple parent devices - your rule will not work. For example, the following rule is invalid as it attempts to match attributes from two parent devices: ... .. .
 
Old 11-30-2008, 11:38 AM   #10
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mandriva, Mandriva, Mandriva. (Three different releases depending on the computer)
Posts: 710

Original Poster
Rep: Reputation: 35
OK, this works:

Code:
KERNEL=="sn-8563645", SUBSYSTEM=="pvrusb2", RUN+="/bin/sh -c '/etc/dynamic/scripts/myscript &'"
It looks, therefore, like it was the syntax of how I was invoking the script. Maybe it's a Mandriva specific thing.

I don't know whether to be glad or frustrated that I was so close from the beginning!
 
Old 11-30-2008, 02:12 PM   #11
tredegar
Guru
 
Registered: May 2003
Location: London, UK
Distribution: Ubuntu 10.04, mostly
Posts: 6,007

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
Quote:
It looks, therefore, like it was the syntax of how I was invoking the script. Maybe it's a Mandriva specific thing.
Maybe it is a "Mandriva thing".
I became annoyed with them, and moved.
But I'll remember
Quote:
RUN+="/bin/sh -c '/etc/dynamic/scripts/myscript &'"
in case of problems later.
You got it working, congratulations.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cat: /etc/udev/rules.d/70-persistent-net.rules: No such file or directory rcg1984 Linux From Scratch 2 09-17-2008 07:02 AM
writing udev rules doralsoral Linux - Software 10 11-19-2006 02:45 AM
slackware-current, udev 0.96, and custom udev rules not working rignes Slackware 6 08-10-2006 03:43 AM
udev rules all_partitions doesn't work arubin Slackware 1 06-10-2006 05:46 PM
need help fixing my udev rules or ivman rules hedpe Linux - Hardware 2 03-18-2006 10:07 AM


All times are GMT -5. The time now is 10:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration