chiark / gitweb /
Merge branch 'docs/udev.xml' of git://github.com/mfwitten/udev
[elogind.git] / extras / rule_generator / rule_generator.functions
index 14c585a86ae442f2dcfca5785b27471790b6ac79..4bec27a1b782d3f15684ea9772b4359eb6313bca 100644 (file)
@@ -1,8 +1,22 @@
 # functions used by the udev rule generator
+
+# Copyright (C) 2006 Marco d'Itri <md@Linux.IT>
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+PATH='/sbin:/bin'
 #
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation version 2 of the License.
 
 PATH='/sbin:/bin'
 
@@ -34,9 +48,10 @@ writeable() {
 
 # Create a lock file for the current rules file.
 lock_rules_file() {
-       [ -e /dev/.udev/ ] || return 0
+       RUNDIR=$(udevadm info --run)
+       [ -e "$RUNDIR" ] || return 0
 
-       RULES_LOCK="/dev/.udev/.lock-${RULES_FILE##*/}"
+       RULES_LOCK="$RUNDIR/.lock-${RULES_FILE##*/}"
 
        retry=30
        while ! mkdir $RULES_LOCK 2> /dev/null; do
@@ -57,7 +72,8 @@ unlock_rules_file() {
 # Choose the real rules file if it is writeable or a temporary file if not.
 # Both files should be checked later when looking for existing rules.
 choose_rules_file() {
-       local tmp_rules_file="/dev/.udev/tmp-rules--${RULES_FILE##*/}"
+       RUNDIR=$(udevadm info --run)
+       local tmp_rules_file="$RUNDIR/tmp-rules--${RULES_FILE##*/}"
        [ -e "$RULES_FILE" -o -e "$tmp_rules_file" ] || PRINT_HEADER=1
 
        if writeable ${RULES_FILE%/*}; then
@@ -92,7 +108,9 @@ find_all_rules() {
        local linkre="$2"
        local match="$3"
 
-       [ -e $RULES_FILE ] || return
-       local search='.*[[:space:],]'"$key"'"\('"$linkre"'\)"[[:space:]]*\(,.*\|\\\|\)$'
-       echo $(sed -n -e "${match}s/${search}/\1/p" $RO_RULES_FILE $RULES_FILE)
+       local search='.*[[:space:],]'"$key"'"('"$linkre"')".*'
+       echo $(sed -n -r -e 's/^#.*//' -e "${match}s/${search}/\1/p" \
+               $RO_RULES_FILE \
+               $([ -e $RULES_FILE ] && echo $RULES_FILE) \
+               2>/dev/null)
 }