You are not logged in.

#1 2016-10-19 11:48:02

Syberic
Member
Registered: 2015-11-13
Posts: 3

Can't get udev rule to work.

I wan't a udev rule to execute xrandr autoconfigure script when some monitor is plugged or unplugged. I read a lot examples and i tired several ready solutions, but none of them seem to work, i have a simple script to test:

$cat /usr/bin/monitor-hotplug 
for output in LVDS-1 VGA-1; do
  echo $output >> /home/syberic/hotplug.log
  cat /sys/class/drm/card0-$output/status >> /home/syberic/hotplug.log
done

It has all the permissions to all users (as far as i know). Theese was set with

sudo chmod 777 /usr/bin/monitor-hotplug

.
And so they look like:

$ls -l /usr/bin | grep monitor-hotplug
-rwxrwxrwx 1 root    root         151 Oct 19 14:15 monitor-hotplug

When i run the script manually it actually produces the desired output:

$cat hotplug.log 
LVDS-1
connected
VGA-1
connected

The udev rule i have:

$cat /etc/udev/rules.d/99-monitor-hotplug.rules 
ACTION=="change", SUBSYSTEM=="drm", KERNEL=="card0", RUN+="/usr/bin/monitor-hotplug"

I did reload the rules with

$sudo udevadm --reload-rules

And the udev event i get when i plug/unplug the vga cable (with properties included):

$sudo udevadm monitor --udev --property
UDEV  [3733.592775] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
ACTION=change
DEVNAME=/dev/dri/card0
DEVPATH=/devices/pci0000:00/0000:00:02.0/drm/card0
DEVTYPE=drm_minor
HOTPLUG=1
ID_FOR_SEAT=drm-pci-0000_00_02_0
ID_PATH=pci-0000:00:02.0
ID_PATH_TAG=pci-0000_00_02_0
MAJOR=226
MINOR=0
PATH=/bin:/usr/bin:/usr/local/bin
SEQNUM=2411
SUBSYSTEM=drm
TAGS=:master-of-seat:uaccess:seat:
USEC_INITIALIZED=17856037

Finally the info insures that KERNEL is card0:

$udevadm info -a -p /devices/pci0000:00/0000:00:02.0/drm/card0
  looking at device '/devices/pci0000:00/0000:00:02.0/drm/card0':
    KERNEL=="card0"
    SUBSYSTEM=="drm"
    DRIVER==""
    ATTR{gt_RP0_freq_mhz}=="1150"
    ATTR{gt_RP1_freq_mhz}=="650"
    ATTR{gt_RPn_freq_mhz}=="650"
    ATTR{gt_act_freq_mhz}=="650"
    ATTR{gt_cur_freq_mhz}=="650"
    ATTR{gt_max_freq_mhz}=="1150"
    ATTR{gt_min_freq_mhz}=="650"

But the script just doesn't run (or running with errors, i don't know how to detect it's actually DID run) from udev environment. Please help me to understand what am i missing.

Offline

#2 2016-10-19 13:33:06

toz
Member
Registered: 2011-10-28
Posts: 494

Re: Can't get udev rule to work.

Make sure your script (monitor-hotplug) starts with a shebang. When run outside of a shell it will not execute.

Offline

Board footer

Powered by FluxBB