I’ve looked through tons of posts, I can’t seem to get a udev rule to trigger when unplugging an HDMI or DP. Nothing shows in:
udevadm monitor --property
Also I made a rules file in udev and it doesn’t trigger the script I have tied to it:
99-monitor-hotplug.rules
ACTION==“change”, SUBSYSTEM==“drm”, ENV{HOTPLUG}==“1”, RUN+=“/usr/local/bin/monitor-hotplug.sh”
OS: Ubuntu 16.04.04 LTS
Video Card: Nvidia GTX 1080
Any thoughts on how to get this to trigger?
generix
November 14, 2018, 9:05am
2
You would have to use either the kernel parameter
nvidia-drm.modeset=1
or have a file in /etc/modprobe.d containing
options nvidia-drm modeset=1
to get the drm sysfs nodes.
sudo cat /sys/module/nvidia_drm/parameters/modeset
should return ‘Y’ if done right.
But I don’t think that will work since the drm monitor stuff in the nvidia driver still isn’t wired up completely. Please check and report back.
Hi generix,
Thanks for your response. I tried:
sudo modprobe -r nvidia-drm
sudo modprobe nvidia-drm modeset=1
then rebooted:
returned N for sudo cat /sys/module/nvidia_drm/parameters/modeset
Then I made an entry in a new file nvidia.conf in /etc/modprobe.d/:
options nvidia-drm modeset=1
and ran: sudo update-initramfs -u
returned N for sudo cat /sys/module/nvidia_drm/parameters/modeset
Then I also found in a post that said grub.cfg should be updated so I edited /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT=“quiet splash i915.modset=1 log_buf_len=1M nvidia-drm.modeset=1”
sudo update-grub
return N for sudo cat /sys/module/nvidia_drm/parameters/modeset
Do you have any other suggestions possible? Thanks for your help so far
generix
November 14, 2018, 6:17pm
4
I missed that you’re on 16.04, there the nvidia modules are renamed.
modify the file in /etc/modprobe.d to read
options nvidia_XXX_drm modeset=1
with XXX being the major version of the nvidia drivers installed and run sudo update-initramfs -u and reboot.
Hi Generix,
Your solution got me the udev rule hotplug event!
I now get this output:
UDEV [52.870606] change /devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0 (drm)
ACTION=change
DEVNAME=/dev/dri/card0
DEVPATH=/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0
DEVTYPE=drm_minor
HOTPLUG=1
ID_FOR_SEAT=drm-pci-0000_01_00_0
ID_PATH=pci-0000:01:00.0
ID_PATH_TAG=pci-0000_01_00_0
MAJOR=226
MINOR=0
SEQNUM=3528
SUBSYSTEM=drm
TAGS=:seat:master-of-seat:uaccess:
USEC_INITIALIZED=2413437
UDEV [53.085358] change /devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0 (drm)
ACTION=change
DEVNAME=/dev/dri/card0
DEVPATH=/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0
DEVTYPE=drm_minor
HOTPLUG=1
ID_FOR_SEAT=drm-pci-0000_01_00_0
ID_PATH=pci-0000:01:00.0
ID_PATH_TAG=pci-0000_01_00_0
MAJOR=226
MINOR=0
SEQNUM=3529
SUBSYSTEM=drm
TAGS=:seat:master-of-seat:uaccess:
USEC_INITIALIZED=2413437
for some reason it doesn’t seem to trigger a response in my 99-monitor-hotplug.sh file /etc/udev/rules.d/:
SUBSYSTEM==“drm”, ACTION==“change”, ENV{HOTPLUG}==“1”, RUN+=“/usr/local/bin/hotplug.sh”
Is there something specific I need to do in this file that I haven’t?
Thanks
generix
November 16, 2018, 7:01pm
6
Depends on what you’re doing in that script. To debug, e.g. add
date >> /var/log/drmhotplug.log
to that script. Use udevadm test to see if the rule is properly triggered.
Hi Generix,
I get this back on trying udevadm test:
calling: test
version 229
syspath parameter missing
Doesn’t seem to be properly triggered, drmhotplug.log doesn’t show up in /var/log/
I can’t seem to find find any info on syspath, could you please assist?
Thanks
generix
November 16, 2018, 10:01pm
8
That was merely a hint, not a full cmdline.
udevadm test --action=change /devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0
though that doesn’t set the HOTPLUG env
Hi Generix,
I was able to get the udev event to trigger based on your advice. For some reason I cannot seem to load an OpenCV based program in the script. When I run the script by itself it loads the OpenCV based program fine. Do you have any thoughts on this?
Thanks
generix
November 16, 2018, 11:35pm
10
If it’s a GUI application, you’ll have to set the DISPLAY and XAUTHORITY variable. Probably also the user so it doesn’t get run as root.
Hi Generix,
I have set these environment variables in my script before the GUI application:
export XAUTHORITY=/home//.Xauthority
export DISPLAY=:0.0
The GUI application still doesn’t seem to load via the Udev rule. I am not sure how to set the user, is it su - username -C ?
Thanks
So I am running with in my 99-monitor-hotplug.sh:
SUBSYSTEM==“drm”, ACTION==“change”, ENV{HOTPLUG}==“1”, RUN+=“/bin/sh -c ‘DISPLAY=:0 XAUTHORITY=/home//.Xauthority /home//Downloads/hotplug.sh’”
Works fine from command line and launches the script and the GUI application runs. I do not see the GUI application run when the udev event is triggered, but I know it is triggered because a file I am writing to in hotplug.sh shows up in /var/log/ .
Any ideas on how to fix?
Thanks
generix
November 20, 2018, 8:34am
13
Don’t really know.
Are you sure the DISPLAY and XAUTHORITY variables are set to the correct values?
Please post the output of
ps aux |grep X
Hi Generix,
Here is the output of ps aux | grep X :
ps aux |grep X
root 1118 4.7 0.6 407492 98936 tty7 Ssl+ 11:37 0:03 /usr/lib/xorg/Xorg -core :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
hom+ 2595 0.0 0.0 21292 1080 pts/1 S+ 11:39 0:00 grep --color=auto X
Thanks
generix
November 20, 2018, 4:46pm
15
Try
XAUTHORITY=/var/run/lightdm/root/:0
Hi Generix,
This is my new 99-monitor-hotplug.sh:
SUBSYSTEM==“drm”, ACTION==“change”, ENV{HOTPLUG}==“1”, RUN+=“/bin/sh -c ‘DISPLAY=:0 XAUTHORITY=/var/run/lightdm/root/:0 /home//Downloads/hotplug.sh’”
The udev rule triggers but still does not start my GUI application.
Thanks for your help so far
generix
November 20, 2018, 5:08pm
17
Since /home//Downloads/hotplug.sh is being run if I understand correctly, start the application in it like
application 2>&1 >>/var/log/application.log
to see what error gets thrown, if any.
Hi Generix,
The file appears empty for application.log . This is an OpenCV based program, does this mean the program is actually launching?
Thanks
generix
November 20, 2018, 5:27pm
19
I’m sorry, wrong order. Try
application >/var/log/application.log 2>&1
Hi Generix,
It says:
/home//Downloads/hotplug.sh: 13: /home//Downloads/hotplug.sh: ./opencvapp: not found
I don’t see how this is possible, I cd into the folder where the opencvapp is earlier in hotplug.sh. Also when I run hotplug.sh it loads opencvapp fine. Any ideas?
Thanks