Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Udev] Règle perso qui ne fonctionne pas (résolu)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index French
View previous topic :: View next topic  
Author Message
sebB
Apprentice
Apprentice


Joined: 02 Mar 2011
Posts: 230
Location: S.O. France

PostPosted: Fri Mar 29, 2013 9:52 pm    Post subject: [Udev] Règle perso qui ne fonctionne pas (résolu) Reply with quote

Bonjour,

Je souhaite créer une règle udev afin de basculer le son et l'écran vers la sortie hdmi automatiquement lorsque le cable est branché.
Je ne comprends pas pourquoi le script de bascule ne fonctionne pas (il ne se lance pas).

udevadm monitor quand je branche ou décranche la prise hdmi
Code:
KERNEL[183812.383953] change   /devices/pci0000:00/0000:00:03.0/0000:01:00.0/drm/card0 (drm)
UDEV  [183812.462182] change   /devices/pci0000:00/0000:00:03.0/0000:01:00.0/drm/card0 (drm)


Ma règle crée dans /etc/udev/rules.d/10-hdmi.rules
Code:
SUBSYSTEM=="drm", DEVPATH=="/devices/pci0000:00/0000:00:03.0/0000:01:00.0/drm/card0", ACTION=="change", RUN+="/bin/sh /home/seb/hdmi.sh"


udevadm test /devices/pci0000:00/0000:00:03.0/0000:01:00.0/drm/card0
Code:
calling: test
version 197
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.

=== trie on-disk ===
tool version:          197
file size:         5481459 bytes
header size             80 bytes
strings            1230475 bytes
nodes              4250904 bytes
load module index
Skip overridden file: /lib64/udev/rules.d/80-net-name-slot.rules.
read rules file: /lib64/udev/rules.d/10-dm.rules
read rules file: /etc/udev/rules.d/10-hdmi.rules
read rules file: /lib64/udev/rules.d/11-dm-lvm.rules
read rules file: /lib64/udev/rules.d/13-dm-disk.rules
read rules file: /lib64/udev/rules.d/40-gentoo.rules
read rules file: /lib64/udev/rules.d/40-usb-media-players.rules
read rules file: /lib64/udev/rules.d/41-libsane.rules
read rules file: /lib64/udev/rules.d/42-usb-hid-pm.rules
read rules file: /lib64/udev/rules.d/50-udev-default.rules
read rules file: /lib64/udev/rules.d/60-cdrom_id.rules
read rules file: /lib64/udev/rules.d/60-persistent-alsa.rules
read rules file: /lib64/udev/rules.d/60-persistent-input.rules
read rules file: /lib64/udev/rules.d/60-persistent-serial.rules
read rules file: /lib64/udev/rules.d/60-persistent-storage-tape.rules
read rules file: /lib64/udev/rules.d/60-persistent-storage.rules
read rules file: /lib64/udev/rules.d/60-persistent-v4l.rules
read rules file: /lib64/udev/rules.d/61-accelerometer.rules
read rules file: /lib64/udev/rules.d/64-btrfs.rules
read rules file: /lib64/udev/rules.d/69-dm-lvm-metad.rules
read rules file: /etc/udev/rules.d/70-persistent-cd.rules
read rules file: /etc/udev/rules.d/70-persistent-net.rules
read rules file: /lib64/udev/rules.d/70-printers.rules
read rules file: /lib64/udev/rules.d/70-udev-acl.rules
read rules file: /lib64/udev/rules.d/75-net-description.rules
read rules file: /lib64/udev/rules.d/75-probe_mtd.rules
read rules file: /lib64/udev/rules.d/75-tty-description.rules
read rules file: /lib64/udev/rules.d/77-nm-olpc-mesh.rules
read rules file: /lib64/udev/rules.d/78-sound-card.rules
read rules file: /lib64/udev/rules.d/80-drivers.rules
read rules file: /etc/udev/rules.d/80-net-name-slot.rules
read rules file: /lib64/udev/rules.d/80-udisks.rules
read rules file: /lib64/udev/rules.d/90-alsa-restore.rules
read rules file: /lib64/udev/rules.d/90-network.rules
read rules file: /lib64/udev/rules.d/95-dm-notify.rules
read rules file: /lib64/udev/rules.d/95-keyboard-force-release.rules
read rules file: /lib64/udev/rules.d/95-keymap.rules
read rules file: /lib64/udev/rules.d/95-udev-late.rules
read rules file: /lib64/udev/rules.d/95-upower-battery-recall-dell.rules
read rules file: /lib64/udev/rules.d/95-upower-battery-recall-fujitsu.rules
read rules file: /lib64/udev/rules.d/95-upower-battery-recall-gateway.rules
read rules file: /lib64/udev/rules.d/95-upower-battery-recall-ibm.rules
read rules file: /lib64/udev/rules.d/95-upower-battery-recall-lenovo.rules
read rules file: /lib64/udev/rules.d/95-upower-battery-recall-toshiba.rules
read rules file: /lib64/udev/rules.d/95-upower-csr.rules
read rules file: /lib64/udev/rules.d/95-upower-hid.rules
read rules file: /lib64/udev/rules.d/95-upower-wup.rules
read rules file: /lib64/udev/rules.d/99-fuse.rules
read rules file: /lib64/udev/rules.d/99-ntfs3g.rules
rules contain 196608 bytes tokens (16384 * 12 bytes), 29617 bytes strings
9476 strings (89912 bytes), 7174 de-duplicated (62598 bytes), 2303 trie nodes used
RUN '/bin/sh /home/seb/hdmi.sh' /etc/udev/rules.d/10-hdmi.rules:1
GROUP 27 /lib64/udev/rules.d/50-udev-default.rules:29
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=0660, uid=0, gid=27
preserve permissions /dev/dri/card0, 020660, uid=0, gid=27
preserve already existing symlink '/dev/char/226:0' to '../dri/card0'
ACTION=add
DEVNAME=/dev/dri/card0
DEVPATH=/devices/pci0000:00/0000:00:03.0/0000:01:00.0/drm/card0
DEVTYPE=drm_minor
MAJOR=226
MINOR=0
SUBSYSTEM=drm
TAGS=:udev-acl:
USEC_INITIALIZED=43021
run: '/bin/sh /home/seb/hdmi.sh'
run: 'udev-acl --action=add --device=/dev/dri/card0'
unload module index


Je tiens a préciser que mon script fonctionne bien, en console aucun problème.
Bien que udevadm semble dire que mon script est lancé, il n'en est rien.
Si je remplace mon script par un simple qui lance firefox, rien ne se passe aussi.

Merci

EDIT:
Si je remplace RUN+="/home/seb/hdmi.sh" par RUN+="/bin/echo test >> /home/seb/test" rien ne se passe aussi


Last edited by sebB on Wed Apr 03, 2013 8:37 am; edited 1 time in total
Back to top
View user's profile Send private message
netfab
Veteran
Veteran


Joined: 03 Mar 2005
Posts: 1590
Location: 127.0.0.1

PostPosted: Sat Mar 30, 2013 6:40 am    Post subject: Reply with quote

Salut,

Tu as redémarré depuis ? Si non, as tu lancé un :
Code:

# udevadm trigger

:?:
Back to top
View user's profile Send private message
guilc
Moderator
Moderator


Joined: 15 Nov 2003
Posts: 3321
Location: Paris - France

PostPosted: Sat Mar 30, 2013 7:57 am    Post subject: Reply with quote

Hello,

Primo, je mettrais le script dans /usr/local/bin et propriété de root, ne serait-ce que par propreté. Et probablement udev a des restrictions sur les endroits où sont les scripts. Ça ne serait pas étonnant, ne serait-ce que par sécurité : là, tu dis à udev (qui tourne en root) d’exécuter un script maitrisé par un utilisateur. C'est juste un gigantesque trou de sécurité...
Donc premier test :
Code:
sudo mv /home/seb/hdmi.sh /usr/local/bin/
sudo chown root:root /usr/local/bin/hdmi.sh
sudo chmod +x /usr/local/bin/hdmi.sh

Et modifie en conséquence la regle udev. Pas besoin de préfixer par /bin/sh non plus :
Code:
SUBSYSTEM=="drm", DEVPATH=="/devices/pci0000:00/0000:00:03.0/0000:01:00.0/drm/card0", ACTION=="change", RUN+="/usr/local/bin/hdmi.sh"



Ensuite, il a quelle tête ton script ? Il ne dépend pas de variables de l'environnement courant de l'utilisateur ?
Parce que, que tu n'arrives pas à lancer firefox dans une règle udev est tout à fait normal. ça a besoin par exemple du DISPLAY, qui n'est défini que dans ta session, pas pour udev.
_________________
Merci de respecter les règles du forum.

Mon site perso : https://www.xwing.info
Mon PORTDIR_OVERLAY : https://gentoo.xwing.info ou layman -a xwing
Back to top
View user's profile Send private message
sebB
Apprentice
Apprentice


Joined: 02 Mar 2011
Posts: 230
Location: S.O. France

PostPosted: Tue Apr 02, 2013 6:06 pm    Post subject: Reply with quote

Merci,

Effectivement, j'avais fait 2 erreurs.
La 1ere dans mon script, erreur de frappe dans le chemin
La 2eme, simplement oublié de relancer udev...

Par contre le script est incomplet dans son execution. La commande xrandr ne se lance pas, le reste fonctionnant.

Ci-joint le script

Code:
#!/bin/bash

state=$(cat /sys/class/drm/card0-HDMI-A-1/status);

if [[ "$state" == "connected" ]]; then
   cat >> "/home/seb/.asoundrc" <<EOF
pcm.!default
{ type hw
  card 1
  device 3
}
EOF
  xrandr --output HDMI-0 --auto
  xrandr --output HDMI-0 --right-of LVDS
else
   rm "/home/seb/.asoundrc"
   xrandr --output HDMI-0 --off
fi
sudo /etc/init.d/alsasound restart
Back to top
View user's profile Send private message
guilc
Moderator
Moderator


Joined: 15 Nov 2003
Posts: 3321
Location: Paris - France

PostPosted: Tue Apr 02, 2013 6:23 pm    Post subject: Reply with quote

Parce que xrandr a besoin... du DISPLAY ;)

Code:
# DISPLAY= xrandr
Can't open display

# DISPLAY=:0 xrandr
Screen 0: minimum 320 x 200, current 1600 x 1200, maximum 8192 x 8192
DVI-I-1 connected 1600x1200+0+0 (normal left inverted right x axis y axis) 432mm x 324mm
   1600x1200      60.0*+
   1280x1024      75.0     60.0 
   1280x960       60.0 
   1152x864       75.0 
   1024x768       75.1     70.1     60.0 
   832x624        74.6 
   800x600        72.2     75.0     60.3     56.2 
   640x480        72.8     75.0     66.7     60.0 
   720x400        70.1 
DVI-I-2 disconnected (normal left inverted right x axis y axis)


Donc si tu ajoutes "DISPLAY=:0", ça devrait le faire.
Après, faut être sur que ce soit toujours :0...
_________________
Merci de respecter les règles du forum.

Mon site perso : https://www.xwing.info
Mon PORTDIR_OVERLAY : https://gentoo.xwing.info ou layman -a xwing
Back to top
View user's profile Send private message
sebB
Apprentice
Apprentice


Joined: 02 Mar 2011
Posts: 230
Location: S.O. France

PostPosted: Wed Apr 03, 2013 8:36 am    Post subject: Reply with quote

Après plusieurs tests, j'ai rajouté dans mon script
Code:
export XAUTHORITY=/home/seb/.Xauthority
export DISPLAY=:0.0

Et ca fonctionne

Merci
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index French All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum