I have a Yubikey which is recognized when inserted. I can also unlock the PC with it however when I remove it my udev rules are not working. Same rule was working in 12.2.
This is what I get when I remove it.
2013-04-11T20:57:42.313145+02:00 laptop kernel: [74421.150286] usb 3-2: USB disconnect, device number 8
Here is my rule
ATTRS{idVendor}=="1050",ATTRS{idProduct}=="0010",GROUP=yubi,MODE="0660"
SUBSYSTEM=="usb",ACTION=="remove",ENV{ID_VENDOR}=="Yubico", PROGRAM="/usr/bin/find /var/run/gdm -name marko -print -quit", ENV{XAUTHLOCALHOSTNAME}="localhost",ENV{DISPLAY}=":0.0",ENV{XAUTHORITY}="$result/database", RUN+="/usr/local/bin/xlock2-lock"
Start with running “udevadm monitor --property” to see which events are reported when device in unplugged and what properties they have. Post result here.
Here is the output.
udevadm monitor --property
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent
KERNEL[145720.101209] remove /devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0/input/input65/event3 (input)
ACTION=remove
DEVNAME=/dev/input/event3
DEVPATH=/devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0/input/input65/event3
MAJOR=13
MINOR=67
SEQNUM=3851
SUBSYSTEM=input
UDEV [145720.102837] remove /devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0/input/input65/event3 (input)
ACTION=remove
DEVLINKS=/dev/input/by-id/usb-Yubico_Yubico_Yubikey_II-event-kbd /dev/input/by-path/pci-0000:26:00.0-usb-0:2:1.0-event-kbd
DEVNAME=/dev/input/event3
DEVPATH=/devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0/input/input65/event3
ID_BUS=usb
ID_INPUT=1
ID_INPUT_KEY=1
ID_INPUT_KEYBOARD=1
ID_MODEL=Yubico_Yubikey_II
ID_MODEL_ENC=Yubico\x20Yubikey\x20II
ID_MODEL_ID=0010
ID_PATH=pci-0000:26:00.0-usb-0:2:1.0
ID_PATH_TAG=pci-0000_26_00_0-usb-0_2_1_0
ID_REVISION=0223
ID_SERIAL=Yubico_Yubico_Yubikey_II
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030101:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=Yubico
ID_VENDOR_ENC=Yubico
ID_VENDOR_ID=1050
MAJOR=13
MINOR=67
SEQNUM=3851
SUBSYSTEM=input
USEC_INITIALIZED=62004855
KERNEL[145720.103188] remove /devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0/input/input65 (input)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0/input/input65
EV=120013
KEY=e080ffdf 1cfffff ffffffff fffffffe
LED=1f
MODALIAS=input:b0003v1050p0010e0111-e0,1,4,11,14,k77,7D,7E,7F,ram4,l0,1,2,3,4,sfw
MSC=10
NAME="Yubico Yubico Yubikey II"
PHYS="usb-0000:26:00.0-2/input0"
PRODUCT=3/1050/10/111
PROP=0
SEQNUM=3852
SUBSYSTEM=input
UNIQ=""
KERNEL[145720.103244] remove /devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0/0003:1050:0010.0039/hidraw/hidraw0 (hidraw)
ACTION=remove
DEVNAME=/dev/hidraw0
DEVPATH=/devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0/0003:1050:0010.0039/hidraw/hidraw0
MAJOR=251
MINOR=0
SEQNUM=3853
SUBSYSTEM=hidraw
KERNEL[145720.103287] remove /devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0/0003:1050:0010.0039 (hid)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0/0003:1050:0010.0039
HID_ID=0003:00001050:00000010
HID_NAME=Yubico Yubico Yubikey II
HID_PHYS=usb-0000:26:00.0-2/input0
MODALIAS=hid:b0003g0001v00001050p00000010
SEQNUM=3854
SUBSYSTEM=hid
KERNEL[145720.103326] remove /devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0 (usb)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0
DEVTYPE=usb_interface
INTERFACE=3/1/1
MODALIAS=usb:v1050p0010d0223dc00dsc00dp00ic03isc01ip01in00
PRODUCT=1050/10/223
SEQNUM=3855
SUBSYSTEM=usb
TYPE=0/0/0
UDEV [145720.103587] remove /devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0/input/input65 (input)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0/input/input65
EV=120013
ID_BUS=usb
ID_FOR_SEAT=input-pci-0000_26_00_0-usb-0_2_1_0
ID_INPUT=1
ID_INPUT_KEY=1
ID_INPUT_KEYBOARD=1
ID_MODEL=Yubico_Yubikey_II
ID_MODEL_ENC=Yubico\x20Yubikey\x20II
ID_MODEL_ID=0010
ID_PATH=pci-0000:26:00.0-usb-0:2:1.0
ID_PATH_TAG=pci-0000_26_00_0-usb-0_2_1_0
ID_REVISION=0223
ID_SERIAL=Yubico_Yubico_Yubikey_II
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030101:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=Yubico
ID_VENDOR_ENC=Yubico
ID_VENDOR_ID=1050
KEY=e080ffdf 1cfffff ffffffff fffffffe
LED=1f
MODALIAS=input:b0003v1050p0010e0111-e0,1,4,11,14,k77,7D,7E,7F,ram4,l0,1,2,3,4,sfw
MSC=10
NAME="Yubico Yubico Yubikey II"
PHYS="usb-0000:26:00.0-2/input0"
PRODUCT=3/1050/10/111
PROP=0
SEQNUM=3852
SUBSYSTEM=input
TAGS=:seat:
UNIQ=""
USEC_INITIALIZED=7962004759
KERNEL[145720.103805] remove /devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2 (usb)
ACTION=remove
BUSNUM=003
DEVNAME=/dev/bus/usb/003/048
DEVNUM=048
DEVPATH=/devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2
DEVTYPE=usb_device
MAJOR=189
MINOR=303
PRODUCT=1050/10/223
SEQNUM=3856
SUBSYSTEM=usb
TYPE=0/0/0
UDEV [145720.103962] remove /devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0/0003:1050:0010.0039/hidraw/hidraw0 (hidraw)
ACTION=remove
DEVNAME=/dev/hidraw0
DEVPATH=/devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0/0003:1050:0010.0039/hidraw/hidraw0
MAJOR=251
MINOR=0
SEQNUM=3853
SUBSYSTEM=hidraw
USEC_INITIALIZED=5720103305
UDEV [145720.104150] remove /devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0/0003:1050:0010.0039 (hid)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0/0003:1050:0010.0039
HID_ID=0003:00001050:00000010
HID_NAME=Yubico Yubico Yubikey II
HID_PHYS=usb-0000:26:00.0-2/input0
MODALIAS=hid:b0003g0001v00001050p00000010
SEQNUM=3854
SUBSYSTEM=hid
USEC_INITIALIZED=20103495
UDEV [145720.104407] remove /devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0 (usb)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2/3-2:1.0
DEVTYPE=usb_interface
INTERFACE=3/1/1
MODALIAS=usb:v1050p0010d0223dc00dsc00dp00ic03isc01ip01in00
PRODUCT=1050/10/223
SEQNUM=3855
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=20103516
UDEV [145720.135385] remove /devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2 (usb)
ACTION=remove
BUSNUM=003
DEVLINKS=/dev/vboxusb/3/48
DEVNAME=/dev/bus/usb/003/048
DEVNUM=048
DEVPATH=/devices/pci0000:00/0000:00:1c.7/0000:26:00.0/usb3/3-2
DEVTYPE=usb_device
DISPLAY=:0.0
ID_BUS=usb
ID_MODEL=Yubico_Yubikey_II
ID_MODEL_ENC=Yubico\x20Yubikey\x20II
ID_MODEL_ID=0010
ID_REVISION=0223
ID_SERIAL=Yubico_Yubico_Yubikey_II
ID_USB_INTERFACES=:030101:
ID_VENDOR=Yubico
ID_VENDOR_ENC=Yubico
ID_VENDOR_ID=1050
MAJOR=189
MINOR=303
PRODUCT=1050/10/223
SEQNUM=3856
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=7961989665
XAUTHLOCALHOSTNAME=localhost
XAUTHORITY=/database
makkan_x:
XAUTHORITY=/database
Well, there is no file or directory under /run/gdm with plain user name in it, so you need to adjust your PROGRAM line:
PROGRAM="/usr/bin/find /var/run/gdm -name marko -print -quit"
I changed that part to be
PROGRAM="/usr/bin/find /var/run/gdm -name auth-for-marko* -print -quit"
Restarted udev
udevadm control --reload
No difference.
udevadm monitor --property
.
.
.
XAUTHORITY=/var/run/gdm/auth-for-marko-70Vw2Q/database
makkan_x:
No difference.
Does it work if you log in as root on vt, export the same variables and run the same program?
Which variables should I export?
I modified the RUN part to be a script that echoes test to a file since RUN+="/usr/local/bin/xlock2-lock" is supposed to start the screensaver.
E-h-h-h … the variables you export in your udev rule:
ENV{XAUTHLOCALHOSTNAME}="localhost",ENV{DISPLAY}=":0.0",ENV{XAUTHORITY}="$result/database",
I exported those three but it is not working.
After searching a bit I found that I can turn on debug on udev. Now I can see that the rule file is being executed and that it is the script that should run that is not working as it should.
Script:
#!/bin/sh
user=marko
XAUTHLOCALHOSTNAME="localhost"
pids=`pgrep -u $user xautolock`
for pid in $pids; do
# find DBUS session bus for this session
DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS \
/proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`
DISP=`grep -z DISPLAY \
/proc/$pid/environ | sed -e 's/DISPLAY=//'`
XAUTH=`grep -z XAUTHORITY \
/proc/$pid/environ | sed -e 's/XAUTHORITY=//'`
DISPLAY=$DISP DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS XAUTHORITY=$XAUTH
su -c 'xautolock -locknow'
done
Error:
2013-04-12T22:41:20.218982+02:00 laptop systemd-udevd[12814]: '/usr/local/bin/xlock2-lock'(err) 'No protocol specified'
2013-04-12T22:41:20.219475+02:00 laptop systemd-udevd[12814]: '/usr/local/bin/xlock2-lock'(err) 'Couldn't connect to :3'
2013-04-12T22:41:20.221485+02:00 laptop systemd-udevd[12814]: '/usr/local/bin/xlock2-lock' [12817] exit with return code 1
Why do you use “su”? Presumably script is already executed as root. Someone recently mentioned that when using su in 12.3 some environment variables in 12.3 were reset, IIRC DISPLAY was one of them.
Good question. I think that was the only way I could get it to work when I made it. Bits from here and there on the net.
Thanks for your help, it is working now that I removed the su.