Setting udev rules in Linux Mint 13

2

What I'm trying to do is set up a udev rule for my HP headphones (usb) with the aid of several tutorials out there.

Created a file ( 90-local.rules ) in /etc/udev/rules.d and added the following:

ACTION="add",SUBSYSTEM="usb", ATTR{vendor}=="Hewlett-Packard", RUN+="sh /home/alex/Scripts/usb.sh"

The problem is nothing happens when I connect the headphones! What am I doing wrong?

note: I did restart udev and the script works also, so it's not that

user1233963

Posted 2012-09-02T20:45:11.720

Reputation: 171

Do this corresponds with the output of monitoring udevadm? – Tamara Wijsman – 2012-09-02T20:48:03.627

If by 'this' you mena the vendor, yes – user1233963 – 2012-09-02T20:50:24.850

What exactly is the usb.sh script doing? – user1686 – 2012-09-03T09:36:37.260

just a simple notify-send call – user1233963 – 2012-09-03T10:35:21.677

Here's the output of udevadm info -a -p /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.3/input/input29 if it helps: http://pastebin.com/95swJYhF

– user1233963 – 2012-09-03T10:38:23.780

Answers

0

Your udev rule is fine. The problem is that your script, as well as udev itself, runs

  1. as root – not as your own user account;
  2. as a service – outside your login session;

and therefore do not have access to your X11 display, or your DBus session bus.

Remember that Linux, as Unix, has supported multiple concurrent login sessions from day one, so there isn't "the user"; there can be multiple users having multiple X11 displays and multiple DBus buses (which might not even have an X11 server attached).

A common workaround is to make the script always choose the first X11 display (by setting DISPLAY=":0" inside the script). However, this is not guaranteed to work – even a single-user PC can have two or more X11 displays running (for example, your own desktop might be at :1, while :0 might be the login screen or not running at all).

user1686

Posted 2012-09-02T20:45:11.720

Reputation: 283 655

changed my rule to: ACTION="add",SUBSYSTEM="usb", ATTR{vendor}=="Hewlett-Packard", RUN+="su alex -c 'DISPLAY=:0 notify-send test'" but still nothing. Note: running "su alex -c 'DISPLAY=:0 notify-send test" as root works. Any ideas? – user1233963 – 2012-09-03T11:22:58.263

@user1233963: Try /bin/su, /usr/bin/su, or whichever is right for your system. – user1686 – 2012-09-03T11:50:06.477

It's /bin/su, tried it, no change. Other ideas? – user1233963 – 2012-09-03T12:00:13.053

0

Try this out first by doing Alt-F2 and in the box there do something like /bin/sh -c "DISPLAY=:0.0 /usr/bin/notify-send foobar" Note all complete paths, and note double quotes around shell command.

Roadowl

Posted 2012-09-02T20:45:11.720

Reputation: 192