Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
udev with variable not working
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
DaggyStyle
Advocate
Advocate


Joined: 22 Mar 2006
Posts: 4884

PostPosted: Sat Jul 20, 2013 7:14 pm    Post subject: udev with variable not working Reply with quote

Hello All,

I'm trying to create a udev rule that sets an variable and uses it in add and remove rules, from what I can see, udev populates the variable but the rules doesn't matches. I've tried with distinct ways (seen in the rule file below).

/etc/udev/rules.d/80-backup-disk.rules:
Code:

# get fstab uuid
IMPORT{program}="/usr/local/bin/backup.sh get_uuid"

# action rules
ACTION=="add", ENV{DEVTYPE}=="partition", ENV{ID_FS_UUID}=="$env{BACKUP_MNT_POINT_FS_UUID}", RUN+="/usr/local/bin/backup.sh start", OPTIONS+="last_rule"
ACTION=="remove", ENV{DEVTYPE}=="partition", ENV{ID_FS_UUID}==ENV{BACKUP_MNT_POINT_FS_UUID}, RUN+="/usr/local/bin/backup.sh stop", OPTIONS+="last_rule"


udevadm test /sys/class/block/sdf1 output:
Code:
calling: test
version 204
=== trie on-disk ===
tool version:          204
file size:         5601550 bytes
header size             80 bytes
strings            1255726 bytes
nodes              4345744 bytes
load module index
Skipping overridden file: /lib64/udev/rules.d/80-net-name-slot.rules.
read rules file: /lib64/udev/rules.d/10-dm.rules
read rules file: /lib64/udev/rules.d/10-virtualbox.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-firmware.rules
read rules file: /lib64/udev/rules.d/50-udev-default.rules
read rules file: /lib64/udev/rules.d/56-hpmud.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/60-vmware.rules
read rules file: /lib64/udev/rules.d/61-accelerometer.rules
read rules file: /run/udev/rules.d/61-dev-root-link.rules
read rules file: /lib64/udev/rules.d/64-btrfs.rules
read rules file: /lib64/udev/rules.d/64-md-raid.rules
read rules file: /lib64/udev/rules.d/65-kvm.rules
read rules file: /lib64/udev/rules.d/66-kpartx.rules
read rules file: /lib64/udev/rules.d/69-dm-lvm-metad.rules
read rules file: /lib64/udev/rules.d/69-libmtp.rules
read rules file: /lib64/udev/rules.d/70-libgphoto2.rules
IMPORT found builtin 'usb_id --export %%p', replacing /lib64/udev/rules.d/70-libgphoto2.rules:13
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/78-sound-card.rules
read rules file: /etc/udev/rules.d/80-backup-disk.rules
read rules file: /lib64/udev/rules.d/80-drivers.rules
skip empty 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/80-udisks2.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: /etc/udev/rules.d/99-seats.rules
rules contain 393216 bytes tokens (32768 * 12 bytes), 37210 bytes strings
23506 strings (197731 bytes), 20274 de-duplicated (163754 bytes), 3233 trie nodes used
GROUP 6 /lib64/udev/rules.d/50-udev-default.rules:50
LINK 'disk/by-id/ata-ST3000DM001-1CH166_W1F27RKP-part1' /lib64/udev/rules.d/60-persistent-storage.rules:43
IMPORT builtin 'blkid' /lib64/udev/rules.d/60-persistent-storage.rules:70
probe /dev/sdf1 raid offset=0
LINK 'disk/by-uuid/5fd24cd9-7238-40c5-864c-fff6164bc70b' /lib64/udev/rules.d/60-persistent-storage.rules:76
LINK 'disk/by-label/backup' /lib64/udev/rules.d/60-persistent-storage.rules:77
LINK 'disk/by-id/wwn-0x5000c5005e3074b4-part1' /lib64/udev/rules.d/60-persistent-storage.rules:81
LINK 'disk/by-partuuid/01fdb30e-f5a8-424a-8917-c2e215371416' /lib64/udev/rules.d/60-persistent-storage.rules:84
LINK 'disk/by-partlabel/Linux\x20filesystem' /lib64/udev/rules.d/60-persistent-storage.rules:85
IMPORT '/usr/local/bin/backup.sh get_uuid' /etc/udev/rules.d/80-backup-disk.rules:2
starting '/usr/local/bin/backup.sh get_uuid'
'/usr/local/bin/backup.sh get_uuid' [17571] exit with return code 0
IMPORT 'udisks-part-id /dev/sdf1' /lib64/udev/rules.d/80-udisks.rules:84
starting 'udisks-part-id /dev/sdf1'
'udisks-part-id /dev/sdf1' [17580] exit with return code 0
handling device node '/dev/sdf1', devnum=b8:81, mode=0660, uid=0, gid=6
preserve permissions /dev/sdf1, 060660, uid=0, gid=6
preserve already existing symlink '/dev/block/8:81' to '../sdf1'
found 'b8:81' claiming '/run/udev/links/\x2fdisk\x2fby-id\x2fata-ST3000DM001-1CH166_W1F27RKP-part1'
creating link '/dev/disk/by-id/ata-ST3000DM001-1CH166_W1F27RKP-part1' to '/dev/sdf1'
preserve already existing symlink '/dev/disk/by-id/ata-ST3000DM001-1CH166_W1F27RKP-part1' to '../../sdf1'
found 'b8:81' claiming '/run/udev/links/\x2fdisk\x2fby-id\x2fwwn-0x5000c5005e3074b4-part1'
creating link '/dev/disk/by-id/wwn-0x5000c5005e3074b4-part1' to '/dev/sdf1'
preserve already existing symlink '/dev/disk/by-id/wwn-0x5000c5005e3074b4-part1' to '../../sdf1'
found 'b8:81' claiming '/run/udev/links/\x2fdisk\x2fby-label\x2fbackup'
creating link '/dev/disk/by-label/backup' to '/dev/sdf1'
preserve already existing symlink '/dev/disk/by-label/backup' to '../../sdf1'
found 'b8:81' claiming '/run/udev/links/\x2fdisk\x2fby-partlabel\x2fLinux\x5cx20filesystem'
creating link '/dev/disk/by-partlabel/Linux\x20filesystem' to '/dev/sdf1'
preserve already existing symlink '/dev/disk/by-partlabel/Linux\x20filesystem' to '../../sdf1'
found 'b8:81' claiming '/run/udev/links/\x2fdisk\x2fby-partuuid\x2f01fdb30e-f5a8-424a-8917-c2e215371416'
creating link '/dev/disk/by-partuuid/01fdb30e-f5a8-424a-8917-c2e215371416' to '/dev/sdf1'
preserve already existing symlink '/dev/disk/by-partuuid/01fdb30e-f5a8-424a-8917-c2e215371416' to '../../sdf1'
found 'b8:81' claiming '/run/udev/links/\x2fdisk\x2fby-uuid\x2f5fd24cd9-7238-40c5-864c-fff6164bc70b'
creating link '/dev/disk/by-uuid/5fd24cd9-7238-40c5-864c-fff6164bc70b' to '/dev/sdf1'
preserve already existing symlink '/dev/disk/by-uuid/5fd24cd9-7238-40c5-864c-fff6164bc70b' to '../../sdf1'
unload module index
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.

ACTION=add
BACKUP_MNT_POINT_FS_UUID=5fd24cd9-7238-40c5-864c-fff6164bc70b
DEVLINKS=/dev/disk/by-id/ata-ST3000DM001-1CH166_W1F27RKP-part1 /dev/disk/by-id/wwn-0x5000c5005e3074b4-part1 /dev/disk/by-label/backup /dev/disk/by-partlabel/Linux\x20filesystem /dev/disk/by-partuuid/01fdb30e-f5a8-424a-8917-c2e215371416 /dev/disk/by-uuid/5fd24cd9-7238-40c5-864c-fff6164bc70b
DEVNAME=/dev/sdf1
DEVPATH=/devices/pci0000:00/0000:00:1f.2/ata6/host5/target5:0:0/5:0:0:0/block/sdf/sdf1
DEVTYPE=partition
ID_ATA=1
ID_ATA_DOWNLOAD_MICROCODE=1
ID_ATA_FEATURE_SET_APM=1
ID_ATA_FEATURE_SET_APM_CURRENT_VALUE=128
ID_ATA_FEATURE_SET_APM_ENABLED=1
ID_ATA_FEATURE_SET_HPA=1
ID_ATA_FEATURE_SET_HPA_ENABLED=1
ID_ATA_FEATURE_SET_PM=1
ID_ATA_FEATURE_SET_PM_ENABLED=1
ID_ATA_FEATURE_SET_SECURITY=1
ID_ATA_FEATURE_SET_SECURITY_ENABLED=0
ID_ATA_FEATURE_SET_SECURITY_ENHANCED_ERASE_UNIT_MIN=332
ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN=332
ID_ATA_FEATURE_SET_SMART=1
ID_ATA_FEATURE_SET_SMART_ENABLED=1
ID_ATA_ROTATION_RATE_RPM=7200
ID_ATA_SATA=1
ID_ATA_SATA_SIGNAL_RATE_GEN1=1
ID_ATA_SATA_SIGNAL_RATE_GEN2=1
ID_ATA_WRITE_CACHE=1
ID_ATA_WRITE_CACHE_ENABLED=1
ID_BUS=ata
ID_FS_LABEL=backup
ID_FS_LABEL_ENC=backup
ID_FS_TYPE=ext3
ID_FS_USAGE=filesystem
ID_FS_UUID=5fd24cd9-7238-40c5-864c-fff6164bc70b
ID_FS_UUID_ENC=5fd24cd9-7238-40c5-864c-fff6164bc70b
ID_FS_VERSION=1.0
ID_MODEL=ST3000DM001-1CH166
ID_MODEL_ENC=ST3000DM001-1CH166\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
ID_PART_ENTRY_DISK=8:80
ID_PART_ENTRY_NAME=Linux\x20filesystem
ID_PART_ENTRY_NUMBER=1
ID_PART_ENTRY_OFFSET=2048
ID_PART_ENTRY_SCHEME=gpt
ID_PART_ENTRY_SIZE=5860531087
ID_PART_ENTRY_TYPE=0fc63daf-8483-4772-8e79-3d69d8477de4
ID_PART_ENTRY_UUID=01fdb30e-f5a8-424a-8917-c2e215371416
ID_PART_TABLE_TYPE=gpt
ID_REVISION=CC24
ID_SERIAL=ST3000DM001-1CH166_W1F27RKP
ID_SERIAL_SHORT=W1F27RKP
ID_TYPE=disk
ID_WWN=0x5000c5005e3074b4
ID_WWN_WITH_EXTENSION=0x5000c5005e3074b4
MAJOR=8
MINOR=81
SUBSYSTEM=block
UDISKS_PARTITION=1
UDISKS_PARTITION_ALIGNMENT_OFFSET=0
UDISKS_PARTITION_LABEL=Linux filesystem
UDISKS_PARTITION_NUMBER=1
UDISKS_PARTITION_OFFSET=1048576
UDISKS_PARTITION_SCHEME=gpt
UDISKS_PARTITION_SIZE=3000591916544
UDISKS_PARTITION_SLAVE=/sys/devices/pci0000:00/0000:00:1f.2/ata6/host5/target5:0:0/5:0:0:0/block/sdf
UDISKS_PARTITION_TYPE=0FC63DAF-8483-4772-8E79-3D69D8477DE4
UDISKS_PARTITION_UUID=01FDB30E-F5A8-424A-8917-C2E215371416
UDISKS_PRESENTATION_NOPOLICY=0
USEC_INITIALIZED=998989572


help one the matter will be highly appreciated.
_________________
Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein
ProjectFootball
Back to top
View user's profile Send private message
teika
n00b
n00b


Joined: 19 Feb 2011
Posts: 68
Location: japan

PostPosted: Sun Jul 21, 2013 12:27 pm    Post subject: Reply with quote

I don't know udev rules well, but as a workaround: You can specify less rules so that it will much more than once. Udev sets envvars to the triggered scripts. Use "printenv" to see what happens each time the script is called. (Messy, but a good last resort.)
_________________
Easy Shift / Ctrl / AltGr ... hack; save your pinkies, type without drudge: topic 865313
Back to top
View user's profile Send private message
DaggyStyle
Advocate
Advocate


Joined: 22 Mar 2006
Posts: 4884

PostPosted: Sun Jul 21, 2013 1:28 pm    Post subject: Reply with quote

teika wrote:
I don't know udev rules well, but as a workaround: You can specify less rules so that it will much more than once. Udev sets envvars to the triggered scripts. Use "printenv" to see what happens each time the script is called. (Messy, but a good last resort.)

there is another simpler solution than what you have suggested, remove the last_rule option, pass ENV{ID_FS_UUID} to the script and handle all there.
but I'd like to exhaust the above approach if possible first.
_________________
Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein
ProjectFootball
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware 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