Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

Udev logging [solved]

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
4 posts • Page 1 of 1
Author
Message
paulj
Guru
Guru
User avatar
Posts: 546
Joined: Thu Sep 30, 2004 4:55 am
Location: Wales, UK

Udev logging [solved]

  • Quote

Post by paulj » Fri May 05, 2017 5:16 pm

I am trying to make a simple rule for udev to run configure xrandr when I plug in an HDMI monitor into my laptop. Pretty straight forward, and basically copied from elsewhere on the web. Anyway, it doesn't seem to do anything, so I decided to set up udev to give more information. Unfortunately, neither using

Code: Select all

udevadm --log-priority="info"
or changing the relevant line in /etc/udev/udev.conf (and rebooting) seems to send any information to /var/log/messages or /var/log/dmesg. Should I be looking somewhere else?

udev version 225-r1 (stable) and openrc (no systemd).

Many thanks!
Last edited by paulj on Mon May 08, 2017 4:49 am, edited 1 time in total.
Top
paulj
Guru
Guru
User avatar
Posts: 546
Joined: Thu Sep 30, 2004 4:55 am
Location: Wales, UK

  • Quote

Post by paulj » Sun May 07, 2017 8:50 am

Since I am not making any progress with this issue, can anyone confirm they can get logging functioning with udev, or eudev. Perhaps the time has come to move over to eudev, since I have no interest in systemd!

Many thanks!
Top
cboldt
Veteran
Veteran
User avatar
Posts: 1046
Joined: Wed Aug 24, 2005 2:54 pm

  • Quote

Post by cboldt » Sun May 07, 2017 11:01 am

I have eudev here, but suspect the logging widgets are similar between the two packages.

I studied the man pages for udev, udevd, udevadm, and udev.conf -- the closes matches I get for your issue are

Code: Select all

udevadm monitor
and for the udevd daemon, setting environment variable $UDEV_LOG

I vaguely recall using `udevadm monitor` to debug a USB-attache device, probably a few years ago. It worked fine for the purpose. Other udevadm commands have been useful to find the details that udev has used to define the system and various devices. I've never changed the log level on the daemon.

The only udev-related entries in logs on my systems are for portage installing the packages, and in dmesg, "udevd[713]: starting version 3.1.5"
Top
paulj
Guru
Guru
User avatar
Posts: 546
Joined: Thu Sep 30, 2004 4:55 am
Location: Wales, UK

  • Quote

Post by paulj » Mon May 08, 2017 4:49 am

Thanks for the reply - you are right - udevadm monitor does give one level of information:

Code: Select all

monitor will print the received events for:
UDEV - the event which udev sends out after rule processing                                                                          
KERNEL - the kernel uevent 

KERNEL[27864.579513] 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
MAJOR=226
MINOR=0
SEQNUM=2973
SUBSYSTEM=drm

UDEV  [27864.584369] 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_PATH=pci-0000:00:02.0
ID_PATH_TAG=pci-0000_00_02_0
MAJOR=226
MINOR=0
SEQNUM=2973
SUBSYSTEM=drm
TAGS=:udev-acl:
USEC_INITIALIZED=13393469
This let me know the message from udev which I want to respond to.

My rule:

Code: Select all

ACTION=="change", SUBSYSTEM=="drm", HOTPLUG=="1", RUN+="/usr/local/bin/hotplug.sh"
As you can see, this should trigger for the above event.

My script:

Code: Select all

#!/bin/bash

# Script to automatically setup HDMI monitor with xrandr on hotplug
# From: https://kdecherf.com/blog/2015/01/16/xrandrudev-hotplug-an-external-screen-no-matter-which-output-it-is/


set -o pipefail

export DISPLAY=:0.0
export XAUTHORITY=/home/paul/.Xauthority

function connect(){
    logger -t udev "HDMI Connected"
    xrandr --output HDMI1 --auto --right-of LVDS1
}
 
function disconnect(){
    logger -t udev "HDMI Disconnected"
    xrandr --output HDMI1 --off
}

xrandr | grep "HDMI connected" &> /dev/null && connect || disconnect
Pretty simple, but never run!

The script permissions:

Code: Select all

-rwxr-xr-x 1 root root 942 May  6 18:18 /usr/local/bin/hotplug.sh
Finally I did manage to get he logging working, but I had to take two steps:
  • Modify /etc/conf.d/udev:

    Code: Select all

    # /etc/conf.d/udev: config file for udev
    
    # Add extra command line options to udevd, use with care
    # udevd --help for possible values
    #udev_opts=""
    
    # Run udevd --debug and write output to /run/udevdebug.log
    # Should not be kept on as it fills diskspace slowly
    udev_debug="YES"
    
  • Modify /etc/udev/udev.conf:

    Code: Select all

    # see udev.conf(5) for details
    
    udev_log="debug"
    
    This gives a more comprehensive log at /run/udevdebug.log. Here is an extract of the activity around the udev startup:

    Code: Select all

    Reading rules file: /lib64/udev/rules.d/95-cd-devices.rules
    Reading rules file: /lib64/udev/rules.d/95-dm-notify.rules
    Reading rules file: /lib64/udev/rules.d/95-upower-csr.rules
    Reading rules file: /lib64/udev/rules.d/95-upower-hid.rules
    Reading rules file: /lib64/udev/rules.d/95-upower-wup.rules
    Reading rules file: /lib64/udev/rules.d/97-hid2hci.rules
    Reading rules file: /lib64/udev/rules.d/99-fuse.rules
    Reading rules file: /etc/udev/rules.d/99-monitor.rules
    unknown key 'HOTPLUG' in /etc/udev/rules.d/99-monitor.rules:1
    invalid rule '/etc/udev/rules.d/99-monitor.rules:1'
    
    As you can see it doesn't like the HOTPLUG key, even though it is in the monitor output, so now I know where to work next.

    Here is the debug log for the event when the monitor is plugged in:

    Code: Select all

    seq 2154 queued, 'change' 'drm'
    Validate module index
    Check if link configuration needs reloading.
    seq 2154 forked new worker [3845]
    seq 2154 running
    IMPORT builtin 'path_id' /lib64/udev/rules.d/60-drm.rules:3
    RUN 'udev-acl --action=$env{ACTION} --device=$env{DEVNAME}' /lib64/udev/rules.d/70-udev-acl.rules:74
    handling device node '/dev/dri/card0', devnum=c226:0, mode=0600, uid=0, gid=0
    preserve already existing symlink '/dev/char/226:0' to '../dri/card0'
    created db file '/run/udev/data/c226:0' for '/devices/pci0000:00/0000:00:02.0/drm/card0'
    starting 'udev-acl --action=change --device=/dev/dri/card0'
    Process 'udev-acl --action=change --device=/dev/dri/card0' succeeded.
    passed device to netlink monitor 0x55fe2bc3b1f0
    seq 2154 processed
    
    So know I know where to check for the next step once the script is valid.

    In case anyone else is here with the same type of issue, don't forget the /run directory is volatile. If you need to save the logfile to work on the contents, copy it somewhere else before rebooting.
Top
Post Reply

4 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy