Some changes in write-cd-rules script
Hi,
I start to make udev-103 packages to test with slackware 11.0,
and i try to drop slackware's custom script to name CD and network devices (my first work is against CD script) and begin to use the provided in udev/extras/rule_generator.
I got the following problems:
1. In a machine with one CD-RW and one DVD drives, the current script doesn't create the /dev/dvd symlink. It detects the CD-RW and creates: cdrom, cdr and cdrw, and to the DVD it creates: cdrom1 and dvd1.
2. The rules created by the write-cd-rules needs to be between udev.rules and cd-aliases-generator.rules. And in slackware we doesn't ship many rules files, but only one udev.rules.
3. K3B uses /dev/writer, and write-cd-rules doesn't create this link.
To solve these problems i made some changes in write-cd-rules.
The changes are in attached patch and does:
1. Always create numbered links, and made the without-number link to the "first one" detect. In the CD-RW and DVD drive it creates to the CD-RW: cdrom0, cdrom, cdr0, cdr, cdwriter, and to DVD it creates: cdrom1, dvd1, dvd. And the users can use /dev/dvd without problems.
2. I added one test to check if there is one rule with the same DEVPATH before create the links. If there is a rule the script only returns 0 and exits. With that i can put the cd-aliases-generator.rules inside udev.rules (i put the cdrom_id.rules in udev.rules, too) and the things still works. The ppl that use split files doesn't have any impact with that.
3. Create the /dev/writer to the most powerful writer:
DVD-RW/DVD-R/DVD-RAM -> CD-RW -> CD-R, in that order.
I hope it can help. The 1 and 3 can be useful to everyone, and
the 2 is useful to ppl that ships only one big file.
Thanks for all,
Piter PUNK
PS> Sugestions and fixes are welcome -;)
Signature · 7 lines
| E-Mail: [email protected] (personal) .|. [email protected] (professional) /V\ // \\ UIN:116043354 Homepage:http://piterpunk.info02.com.br /( )\ ^`~'^ ----> Slackware Linux - The Best One! <---- #105432
extras/rule_generator/write_cd_rules +50 -19
@@ -50,29 +50,60 @@ exit 1 fi -# Prevent concurrent processes from modifying the file at the same time. -lock_rules_file -# Check if the rules file is writeable. -choose_rules_file +if ! egrep "^ENV{ID_CDROM}==\"\?\*\", ENV{ID_PATH}==\"$ID_PATH\"" /etc/udev/rules.d/* &>/dev/null ; then + # Prevent concurrent processes from modifying the file at the same time. + lock_rules_file + + # Check if the rules file is writeable. + choose_rules_file + + link_num=$(find_next_available 'cdrom[0-9]*') + [ "$link_num" = "" ] && link_num=0 + + match="ENV{ID_CDROM}==\"?*\", ENV{ID_PATH}==\"$ID_PATH\"" + + comment="$ID_MODEL ($ID_PATH)" + + write_rule "$match" "cdrom$link_num" "$comment" + [ "x$(find_next_available 'cdrom')" = "x" ] && \ + write_rule "$match" "cdrom" + + if [ "$ID_CDROM_DVD" ]; then + write_rule "$match" "dvd$link_num" + [ "x$(find_next_available 'dvd')" = "x" ] && \ + write_rule "$match" "dvd" + if [ "$ID_CDROM_DVD_R" -o "$ID_CDROM_DVD_RW" -o "$ID_CDROM_DVD_RAM" ]; then + write_rule "$match" "dvdrw$link_num" + [ "x$(find_next_available 'dvdwriter')" = "x" ] && \ + write_rule "$match" "dvdwriter" + [ "x$(find_next_available 'writer')" = "x" ] && \ + write_rule "$match" "writer" + fi + fi + + if [ "$ID_CDROM_CD_R" ]; then + write_rule "$match" "cdr$link_num" + [ "x$(find_next_available 'cdwriter')" = "x" ] && \ + write_rule "$match" "cdwriter" + [ "x$(find_next_available 'cdr')" = "x" ] && \ + write_rule "$match" "cdr" + if [ "$ID_CDROM_CD_RW" ]; then + write_rule "$match" "cdrw$link_num" + [ "x$(find_next_available 'cdrw')" = "x" ] && \ + write_rule "$match" "cdrw" + [ "x$(find_next_available 'writer')" = "x" ] && \ + write_rule "$match" "writer" + fi + [ "x$(find_next_available 'writer')" = "x" ] && \ + write_rule "$match" "writer" + fi -link_num=$(find_next_available 'cdrom[0-9]*') -match="ENV{ID_CDROM}==\"?*\", ENV{ID_PATH}==\"$ID_PATH\"" + unlock_rules_file -comment="$ID_MODEL ($ID_PATH)" - - write_rule "$match" "cdrom$link_num" "$comment" -[ "$ID_CDROM_CD_R" -o "$ID_CDROM_CD_RW" ] && \ - write_rule "$match" "cdrw$link_num" -[ "$ID_CDROM_DVD" ] && \ - write_rule "$match" "dvd$link_num" -[ "$ID_CDROM_DVD_R" -o "$ID_CDROM_DVD_RW" -o "$ID_CDROM_DVD_RAM" ] && \ - write_rule "$match" "dvdrw$link_num" - -unlock_rules_file - -echo $SYMLINKS + echo $SYMLINKS +fi exit 0
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 1 line · Piter PUNK
I got the following problems:
Your first problem is that you do not understand the locking rules used by the script.
extras/rule_generator/write_cd_rules line 56
Quoted 3 lines
extras/rule_generator/write_cd_rules +3
-0+if ! egrep "^ENV{ID_CDROM}=\"\?\*\", ENV{ID_PATH}=\"$ID_PATH\"" /etc/udev/rules.d/* &>/dev/null ; then + # Prevent concurrent processes from modifying the file at the same time. + lock_rules_file
This creates a race.
Also, checking all files in the directory is broken because some may not be rules files.
I think that there are other problems, but I have not examined carefully the script.
Signature · 12 lines
ciao, Marco ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642 _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net [email protected] https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 8 lines · md
Your first problem is that you do not understand the locking rules used by the script.
extras/rule_generator/write_cd_rules line 56
Quoted 3 lines
extras/rule_generator/write_cd_rules +3
-0+if ! egrep "^ENV{ID_CDROM}=\"\?\*\", ENV{ID_PATH}=\"$ID_PATH\"" /etc/udev/rules.d/* &>/dev/null ; then + # Prevent concurrent processes from modifying the file at the same time. + lock_rules_fileThis creates a race.
You are correct. The test needs to be after the lock_rules_file. In our script (cdrom-symlinks.sh) it is after the locking.
Quoted 2 lines
Also, checking all files in the directory is broken because some may not be rules files.
I don't know that. I was thinking udev looks in all files under /etc/udev/rules.d. Now i test renaming some files to DONTRUN, README, etc.. and it really doesn't read this files. Changing the grep to *.rules will solve it.
Quoted 2 lines
I think that there are other problems, but I have not examined carefully the script.
Good, i will be happy with your feedback.
Piter PUNK
Signature · 17 lines
| E-Mail: [email protected] (personal) .|. [email protected] (professional) /V\ // \\ UIN:116043354 Homepage:http://piterpunk.info02.com.br /( )\ ^`~'^ ----> Slackware Linux - The Best One! <---- #105432 ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642 _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net [email protected] https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel